Skip to content

Commit

Permalink
feat: log elapsed cron job time (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw authored Jul 3, 2024
1 parent 15f3493 commit 1cf119c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/cron-jobs-core/src/creator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cron from "node-cron";

import { Stopwatch } from "@homarr/common";
import type { MaybePromise } from "@homarr/common/types";

import type { Logger } from "./logger";
Expand Down Expand Up @@ -27,9 +28,14 @@ const createCallback = <TAllowedNames extends string, TName extends TAllowedName
const catchingCallbackAsync = async () => {
try {
creatorOptions.logger.logDebug(`The callback of '${name}' cron job started`);
const stopwatch = new Stopwatch();
await creatorOptions.beforeCallback?.(name);
const beforeCallbackTook = stopwatch.getElapsedInHumanWords();
await callback();
creatorOptions.logger.logInfo(`The callback of '${name}' cron job succeeded`);
const callbackTook = stopwatch.getElapsedInHumanWords();
creatorOptions.logger.logInfo(
`The callback of '${name}' cron job succeeded (before callback took ${beforeCallbackTook}, callback took ${callbackTook})`,
);
await creatorOptions.onCallbackSuccess?.(name);
} catch (error) {
creatorOptions.logger.logError(error);
Expand Down

0 comments on commit 1cf119c

Please sign in to comment.