diff --git a/app/org/thp/cortex/models/Worker.scala b/app/org/thp/cortex/models/Worker.scala index 567087ab4..e5085c59f 100644 --- a/app/org/thp/cortex/models/Worker.scala +++ b/app/org/thp/cortex/models/Worker.scala @@ -1,22 +1,22 @@ package org.thp.cortex.models import javax.inject.{Inject, Singleton} - -import scala.concurrent.Future -import scala.util.Try - -import play.api.libs.json.{JsObject, JsString, Json} - import org.elastic4play.models.JsonFormat.enumFormat import org.elastic4play.models.{AttributeDef, BaseEntity, ChildModelDef, EntityDef, HiveEnumeration, AttributeFormat ⇒ F, AttributeOption ⇒ O} import org.elastic4play.utils.Hasher - import org.thp.cortex.models.JsonFormat.workerTypeFormat +import play.api.libs.json.{JsObject, JsString, Json} + +import scala.concurrent.Future +import scala.util.Try object RateUnit extends Enumeration with HiveEnumeration { type Type = Value - val Day = Value(1) - val Month = Value(30) + val Second = Value(1) + val Minute = Value(60) + val Hour = Value(60 * 60) + val Day = Value(60 * 60 * 24) + val Month = Value(60 * 60 * 24 * 30) implicit val reads = enumFormat(this) } diff --git a/app/org/thp/cortex/services/JobSrv.scala b/app/org/thp/cortex/services/JobSrv.scala index 49ca1a275..1b2b6944b 100644 --- a/app/org/thp/cortex/services/JobSrv.scala +++ b/app/org/thp/cortex/services/JobSrv.scala @@ -327,7 +327,7 @@ class JobSrv( import org.elastic4play.services.QueryDSL._ val now = new Date().getTime logger.info(s"Checking rate limit on worker ${worker.name()} from ${new Date(now - rateUnit.id.toLong * 24 * 60 * 60 * 1000)}") - stats(and("createdAt" ~>= (now - rateUnit.id.toLong * 24 * 60 * 60 * 1000), "workerId" ~= worker.id), Seq(selectCount)).map { s ⇒ + stats(and("createdAt" ~>= (now - rateUnit.id.toLong * 1000), "workerId" ~= worker.id), Seq(selectCount)).map { s ⇒ val count = (s \ "count").as[Long] logger.info(s"$count analysis found (limit is $rate)") count < rate