diff --git a/src/monitor.ts b/src/monitor.ts index 87f9b21..43200a8 100644 --- a/src/monitor.ts +++ b/src/monitor.ts @@ -54,7 +54,8 @@ function getDuration(start: Date, end: Date) { export default async function monitorAsync(execute: () => Promise): Promise { // Tell Cronitor that the job is running const start = new Date(); - await fetch(buildURL({state: "run"}).toString()); + const series = start.getTime().toString(); + await fetch(buildURL({state: "run", series}).toString()); console.log("Cronitor: Job started") // Execute the function, provide try/catch @@ -63,14 +64,14 @@ export default async function monitorAsync(execute: () => Promise): result = await execute(); } catch (error) { const duration = getDuration(start, new Date()); - await fetch(buildURL({state: "fail", message: error instanceof Error ? error.message : undefined, metric: {duration}}).toString()); + await fetch(buildURL({state: "fail", series, message: error instanceof Error ? error.message : undefined, metric: {duration}}).toString()); throw error; } // Tell Cronitor that the job is complete (success) console.log("Cronitor: Job completed") const duration = getDuration(start, new Date()); - await fetch(buildURL({state: "complete", metric: {duration}}).toString()); + await fetch(buildURL({state: "complete", series, metric: {duration}}).toString()); return result as T; } \ No newline at end of file