diff --git a/src/db.py b/src/db.py index 39b06f44..1b8900ac 100644 --- a/src/db.py +++ b/src/db.py @@ -78,11 +78,16 @@ def get_job_ids(self) -> List[JobId]: def cancel_job(self, job: JobId) -> None: """ Sets the job status to cancelled """ - self.redis.hmset(job.key, {"status": "cancelled"}) + self.redis.hmset( + job.key, {"status": "cancelled", "finished": int(time())} + ) def fail_job(self, job: JobId, message: str) -> None: """ Sets the job status to failed. """ - self.redis.hmset(job.key, {"status": "failed", "error": message}) + self.redis.hmset( + job.key, + {"status": "failed", "error": message, "finished": int(time())}, + ) def get_job(self, job: JobId) -> JobSchema: data = self.redis.hgetall(job.key) @@ -93,6 +98,7 @@ def get_job(self, job: JobId) -> JobSchema: rule_author=data.get("rule_author", None), raw_yara=data.get("raw_yara", "ERROR"), submitted=data.get("submitted", 0), + finished=data.get("finished", None), priority=data.get("priority", "medium"), files_processed=int(data.get("files_processed", 0)), files_matched=int(data.get("files_matched", 0)), @@ -264,7 +270,9 @@ def agent_start_job( def agent_finish_job(self, job: JobId) -> None: new_agents = self.redis.hincrby(job.key, "agents_left", -1) if new_agents <= 0: - self.redis.hmset(job.key, {"status": "done"}) + self.redis.hmset( + job.key, {"status": "done", "finished": int(time())} + ) def has_pending_search_tasks(self, agent_id: str, job: JobId) -> bool: return self.redis.llen(f"job-ds:{agent_id}:{job.hash}") == 0 diff --git a/src/mqueryfront/src/QueryTimer.js b/src/mqueryfront/src/QueryTimer.js index d3893235..7b6e8fb7 100644 --- a/src/mqueryfront/src/QueryTimer.js +++ b/src/mqueryfront/src/QueryTimer.js @@ -37,10 +37,15 @@ class QueryTimer extends Component { } render() { - if (!this.props.job.submitted || this.props.isFinished) { + if (!this.props.job.submitted) { return null; } + if (this.props.isFinished) { + const duration = this.props.job.finished - this.props.job.submitted; + return Duration: {this.getRenderTime(duration)}; + } + let durationSec; if (this.props.duration) { durationSec = this.state.currentTime - this.props.job.submitted; diff --git a/src/schema.py b/src/schema.py index fa002602..d3d39992 100644 --- a/src/schema.py +++ b/src/schema.py @@ -10,6 +10,7 @@ class JobSchema(BaseModel): rule_author: Optional[str] raw_yara: str submitted: int + finished: Optional[int] priority: str files_processed: int files_matched: int