mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-16 18:11:20 -06:00
Add precise time-based series parameter for telemetry
This commit is contained in:
@@ -54,7 +54,8 @@ function getDuration(start: Date, end: Date) {
|
|||||||
export default async function monitorAsync<T = any>(execute: () => Promise<T>): Promise<T> {
|
export default async function monitorAsync<T = any>(execute: () => Promise<T>): Promise<T> {
|
||||||
// Tell Cronitor that the job is running
|
// Tell Cronitor that the job is running
|
||||||
const start = new Date();
|
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")
|
console.log("Cronitor: Job started")
|
||||||
|
|
||||||
// Execute the function, provide try/catch
|
// Execute the function, provide try/catch
|
||||||
@@ -63,14 +64,14 @@ export default async function monitorAsync<T = any>(execute: () => Promise<T>):
|
|||||||
result = await execute();
|
result = await execute();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const duration = getDuration(start, new Date());
|
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;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell Cronitor that the job is complete (success)
|
// Tell Cronitor that the job is complete (success)
|
||||||
console.log("Cronitor: Job completed")
|
console.log("Cronitor: Job completed")
|
||||||
const duration = getDuration(start, new Date());
|
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;
|
return result as T;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user