Skip to content

Commit

Permalink
#53 Fix atMost parameter in cortex waitreport call
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Dec 7, 2016
1 parent b7c897a commit c165260
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion thehive-cortex/app/connectors/cortex/models/Job.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class JobModel @Inject() (artifactModel: ArtifactModel) extends ChildModelDef[Jo
}
}
class Job(model: JobModel, attributes: JsObject) extends EntityDef[JobModel, Job](model, attributes) with JobAttributes {
override def toJson = super.toJson + ("report" report().fold[JsValue](JsObject(Nil))(r Json.parse(r)))
override def toJson = super.toJson + ("report" report().fold[JsValue](JsObject(Nil))(r Json.parse(r))) // FIXME is parse fails (invalid report)
}

case class CortexJob(id: String, analyzerId: String, artifact: CortexArtifact, date: Date, status: JobStatus.Type, cortexIds: List[String] = Nil) extends CortexModel[CortexJob] {
Expand Down
11 changes: 7 additions & 4 deletions thehive-cortex/app/connectors/cortex/services/CortexSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.nio.file.{ Path, Paths }
import javax.inject.{ Inject, Singleton }

import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.duration.Duration
import scala.concurrent.duration.DurationInt
import scala.language.implicitConversions
import scala.util.{ Failure, Success }
import scala.util.control.NonFatal
Expand Down Expand Up @@ -140,12 +140,15 @@ class CortexSrv @Inject() (

def updateJobWithCortex(jobId: String, cortexJobId: String, cortex: CortexClient)(implicit authContext: AuthContext): Unit = {
log.debug(s"Requesting status of job $cortexJobId in cortex ${cortex.name} in order to update job ${jobId}")
cortex.waitReport(cortexJobId, Duration.Inf) andThen {
cortex.waitReport(cortexJobId, 1.minute) andThen {
case Success(j)
val status = (j \ "status").asOpt[JobStatus.Type].getOrElse(JobStatus.Failure)
val report = (j \ "report").as[JsObject]
val report = (j \ "report").asOpt[JsObject].getOrElse(JsObject(Nil)).toString
log.debug(s"Job $cortexJobId in cortex ${cortex.name} has finished with status $status, updating job ${jobId}")
update(jobId, Fields.empty.set("status", status.toString).set("report", report))
update(jobId, Fields.empty.set("status", status.toString).set("report", report)).onComplete {
case Failure(e) log.error(s"Update job fails", e)
case _
}
case Failure(e)
log.debug(s"Request of status of job $cortexJobId in cortex ${cortex.name} fails, restarting ...")
updateJobWithCortex(jobId, cortexJobId, cortex)
Expand Down

0 comments on commit c165260

Please sign in to comment.