1

We are using metronome, and we want to create a dashboard for our jobs scheduled by it against its rest API.

Alas, the job endpoint

/v1/jobs

does not contain the last state, i.e. success or failure, but only its configuration.

Googling on how to get the history of a job, I found out that I can query the job history through embed=history GET parameter for each jobId.

I could now combine fetching the id list so that I could then fetch each job's history through:

 /v1/jobs/{job_id}?embed=history

Yet this includes all the runs and also requires us to fetch each job individually.

Is there a way to get the metronome job status without querying all the jobs one by one?

k0pernikus
  • 60,309
  • 67
  • 216
  • 347

1 Answers1

1

You can click on each GET or POST endpoint on the official docs to see if it supports additional query params.

The endpoint for jobs indeed supports historic data

Metronome

As you can see you can use embed=history or embed=historySummary, for your use-case embed=historySummary is better suited as it only contains the timestamps of the last run in this form and is less expensive and time-consuming:

[
{
    "id": "your_job_id",
    "historySummary": {
        "failureCount": 6, 
        "lastFailureAt": "2018-01-26T12:18:46.406+0000", 
        "lastSuccessAt": "2018-04-19T13:50:14.132+0000", 
        "successCount": 226
    }, 
    ...
 },
 ...
 ]

You can compare those dates to figure out if the last run was successful. Yet keep in mind that lastFailureAt and lastSuccessAt might be null as a job might have been never run in the first place:

  {
    "id": "job-that-never-ran",
    "labels": {},
    "run": {
    ...
    }
    "historySummary": {
      "successCount": 0,
      "failureCount": 0,
      "lastSuccessAt": null,
      "lastFailureAt": null
    }
  },
k0pernikus
  • 60,309
  • 67
  • 216
  • 347