Skip to content

Commit

Permalink
Show query time after the query is done (#175)
Browse files Browse the repository at this point in the history
Co-authored-by: Itay Cohen <[email protected]>
  • Loading branch information
msm-code and ITAYC0HEN authored May 18, 2020
1 parent bcc8699 commit 834b337
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)),
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/mqueryfront/src/QueryTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>Duration: {this.getRenderTime(duration)}</i>;
}

let durationSec;
if (this.props.duration) {
durationSec = this.state.currentTime - this.props.job.submitted;
Expand Down
1 change: 1 addition & 0 deletions src/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 834b337

Please sign in to comment.