Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show query time after the query is done #175

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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