Skip to content

Commit

Permalink
#85 permit to specify job cache in analyzer config
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 9, 2018
1 parent df80aae commit fd8b77f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/org/thp/cortex/models/Analyzer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ trait AnalyzerAttributes { _: AttributeDef ⇒
val configuration = attribute("configuration", F.textFmt, "Configuration of analyzer", O.sensitive)
val rate = optionalAttribute("rate", F.numberFmt, "Number ")
val rateUnit = optionalAttribute("rateUnit", F.enumFmt(RateUnit), "")
val jobCache = optionalAttribute("jobCache", F.numberFmt, "")
}

@Singleton
Expand Down
7 changes: 4 additions & 3 deletions app/org/thp/cortex/services/JobSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.scalactic.{ Bad, Good, One, Or }
import org.thp.cortex.models._
import play.api.libs.json._
import play.api.{ Configuration, Logger }
import scala.concurrent.duration.Duration
import scala.concurrent.duration._
import scala.concurrent.{ ExecutionContext, Future }
import scala.sys.process.{ Process, ProcessIO }
import scala.util.control.NonFatal
Expand Down Expand Up @@ -300,7 +300,8 @@ class JobSrv(
}

def findSimilarJob(analyzer: Analyzer, dataType: String, dataAttachment: Either[String, Attachment], tlp: Long, parameters: JsObject): Future[Option[Job]] = {
if (jobCache.length == 0) {
val cache = analyzer.jobCache().fold(jobCache)(_.minutes)
if (cache.length == 0) {
logger.info("Job cache is disabled")
Future.successful(None)
}
Expand All @@ -312,7 +313,7 @@ class JobSrv(
"analyzerId" ~= analyzer.id,
"status" ~!= JobStatus.Failure,
"status" ~!= JobStatus.Deleted,
"startDate" ~>= (now - jobCache.toMillis),
"startDate" ~>= (now - cache.toMillis),
"dataType" ~= dataType,
"tlp" ~= tlp,
dataAttachment.fold(data "data" ~= data, attachment "attachment.id" ~= attachment.id),
Expand Down

0 comments on commit fd8b77f

Please sign in to comment.