Skip to content

Commit

Permalink
Murdock: Increment metric counters in _process_job
Browse files Browse the repository at this point in the history
The individual job_{prepare,finalize} are expected to throw exceptions.
If one of these throw an exception, the execution continues potentially
without incrementing the metric counters. Pulling the counters outside
these functions ensure that they are always incremented.

Grouping them in the same function call makes it also easier to track
their increments
  • Loading branch information
bergzand authored and aabadie committed Mar 2, 2023
1 parent fa07c66 commit 8f38a43
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions murdock/murdock.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async def _process_job(self, job: MurdockJob):
else:
logger.info("Processing job") # type: ignore[union-attr]
self._set_worker_metric(job, "prepare")
self.job_start_counter.inc()
try:
await self.job_prepare(job)
except Exception as exc:
Expand All @@ -196,6 +197,7 @@ async def _process_job(self, job: MurdockJob):
logger.warning(
"Finalize step failed", exception=repr(exc), state=job.state
)
self.job_status_counter.labels(status=job.state).inc()
self._remove_worker_metric()
logger.info("job completed", state=job.state)

Expand Down Expand Up @@ -233,7 +235,6 @@ async def job_prepare(self, job: MurdockJob):
"target_url": job.details_url,
},
)
self.job_start_counter.inc()
await self.reload_jobs()

async def job_finalize(self, job: MurdockJob):
Expand Down Expand Up @@ -277,7 +278,6 @@ async def job_finalize(self, job: MurdockJob):
job.state == "stopped" and self.store_stopped_jobs
):
await self.db.insert_job(job)
self.job_status_counter.labels(status=job.state).inc()
await self.reload_jobs()

async def add_job_to_queue(self, job: MurdockJob):
Expand Down

0 comments on commit 8f38a43

Please sign in to comment.