Files
klz-cables.com/.pnpm-store/v10/files/3c/fb21024267f25adbbfd4b841e0ff102725fe200a98d9c19010f271c7333ff21ac33e6affc2f2d62302d9a98a303b336163da7e022fd7d37faf48136e8a9e47
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

79 lines
2.3 KiB
Plaintext

import { withMonitor, captureException } from '@sentry/core';
import { replaceCronNames } from './common.js';
/**
* Wraps the `node-cron` library with check-in monitoring.
*
* ```ts
* import * as Sentry from "@sentry/node";
* import * as cron from "node-cron";
*
* const cronWithCheckIn = Sentry.cron.instrumentNodeCron(cron);
*
* cronWithCheckIn.schedule(
* "* * * * *",
* () => {
* console.log("running a task every minute");
* },
* { name: "my-cron-job" },
* );
* ```
*/
function instrumentNodeCron(
lib,
monitorConfig = {},
) {
return new Proxy(lib, {
get(target, prop) {
if (prop === 'schedule' && target.schedule) {
// When 'get' is called for schedule, return a proxied version of the schedule function
return new Proxy(target.schedule, {
apply(target, thisArg, argArray) {
const [expression, callback, options] = argArray;
const name = options?.name;
const timezone = options?.timezone;
if (!name) {
throw new Error('Missing "name" for scheduled job. A name is required for Sentry check-in monitoring.');
}
const monitoredCallback = async (...args) => {
return withMonitor(
name,
async () => {
// We have to manually catch here and capture the exception because node-cron swallows errors
// https://github.com/node-cron/node-cron/issues/399
try {
return await callback(...args);
} catch (e) {
captureException(e, {
mechanism: {
handled: false,
type: 'auto.function.node-cron.instrumentNodeCron',
},
});
throw e;
}
},
{
schedule: { type: 'crontab', value: replaceCronNames(expression) },
timezone,
...monitorConfig,
},
);
};
return target.apply(thisArg, [expression, monitoredCallback, options]);
},
});
} else {
return target[prop ];
}
},
});
}
export { instrumentNodeCron };
//# sourceMappingURL=node-cron.js.map