Skip to content

Commit

Permalink
Expose metrics in sync protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodearnest committed Dec 11, 2023
1 parent 20e0235 commit 6c71080
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions jobrunner/executors/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pipeline.legacy import get_all_output_patterns_from_project_file

from jobrunner import config, models
from jobrunner import config, record_stats
from jobrunner.executors import volumes
from jobrunner.job_executor import (
ExecutorAPI,
Expand All @@ -22,7 +22,7 @@
JobStatus,
Privacy,
)
from jobrunner.lib import database, datestr_to_ns_timestamp, docker
from jobrunner.lib import datestr_to_ns_timestamp, docker
from jobrunner.lib.git import checkout_commit
from jobrunner.lib.path_utils import list_dir_with_ignore_patterns
from jobrunner.lib.string_utils import tabulate
Expand Down
7 changes: 7 additions & 0 deletions jobrunner/record_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def main():
time.sleep(max(2, config.STATS_POLL_INTERVAL - elapsed))


def get_metrics_for_job(job_id):
try:
return database.find_one(models.ExecutorJob, id=job_id).metrics
except ValueError:
return {}


def record_tick_trace(last_run, active_jobs):
"""Record a period tick trace of current jobs.
Expand Down
5 changes: 3 additions & 2 deletions jobrunner/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import requests

from jobrunner import config, queries
from jobrunner import config, queries, record_stats
from jobrunner.create_or_update_jobs import create_or_update_jobs
from jobrunner.lib.database import find_where, select_values
from jobrunner.lib.log_utils import configure_logging, set_log_context
Expand Down Expand Up @@ -143,13 +143,14 @@ def job_to_remote_format(job):
Convert our internal representation of a Job into whatever format the
job-server expects
"""

return {
"identifier": job.id,
"job_request_id": job.job_request_id,
"action": job.action,
"run_command": job.run_command,
"status": job.state.value,
"status_code": job.status_code.value if job.status_code else "",
"status_code": job.status_code.value,
"status_message": job.status_message or "",
"created_at": job.created_at_isoformat,
"updated_at": job.updated_at_isoformat,
Expand Down
2 changes: 1 addition & 1 deletion tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def job_factory(job_request=None, **kwargs):

if "started_at" not in kwargs:
status_code = kwargs.get("status_code", values["status_code"])
if status_code >= StatusCode.EXECUTING:
if status_code and status_code >= StatusCode.EXECUTING:
values["started_at"] = int(timestamp)

if "status_code_updated_at" not in kwargs:
Expand Down

0 comments on commit 6c71080

Please sign in to comment.