Files
klz-cables.com/.pnpm-store/v10/files/24/b6535c6e55c674e977ec3e4791da0f920adeb1140f24952145bd07ca9ff0b3928e95ffc0c40a709b17e7054c3a9556a8524359cc69d4d800a77c73ae952574
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

123 lines
3.4 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const core = require('@sentry/core');
const common = require('./common.js');
const ERROR_TEXT = 'Automatic instrumentation of CronJob only supports crontab string';
/**
* Instruments the `cron` library to send a check-in event to Sentry for each job execution.
*
* ```ts
* import * as Sentry from '@sentry/node';
* import { CronJob } from 'cron';
*
* const CronJobWithCheckIn = Sentry.cron.instrumentCron(CronJob, 'my-cron-job');
*
* // use the constructor
* const job = new CronJobWithCheckIn('* * * * *', () => {
* console.log('You will see this message every minute');
* });
*
* // or from
* const job = CronJobWithCheckIn.from({ cronTime: '* * * * *', onTick: () => {
* console.log('You will see this message every minute');
* });
* ```
*/
function instrumentCron(lib, monitorSlug) {
let jobScheduled = false;
return new Proxy(lib, {
construct(target, args) {
const [cronTime, onTick, onComplete, start, timeZone, ...rest] = args;
if (typeof cronTime !== 'string') {
throw new Error(ERROR_TEXT);
}
if (jobScheduled) {
throw new Error(`A job named '${monitorSlug}' has already been scheduled`);
}
jobScheduled = true;
const cronString = common.replaceCronNames(cronTime);
async function monitoredTick(context, onComplete) {
return core.withMonitor(
monitorSlug,
async () => {
try {
await onTick(context, onComplete);
} catch (e) {
core.captureException(e, {
mechanism: {
handled: false,
type: 'auto.function.cron.instrumentCron',
},
});
throw e;
}
},
{
schedule: { type: 'crontab', value: cronString },
timezone: timeZone || undefined,
},
);
}
return new target(cronTime, monitoredTick, onComplete, start, timeZone, ...rest);
},
get(target, prop) {
if (prop === 'from') {
return (param) => {
const { cronTime, onTick, timeZone } = param;
if (typeof cronTime !== 'string') {
throw new Error(ERROR_TEXT);
}
if (jobScheduled) {
throw new Error(`A job named '${monitorSlug}' has already been scheduled`);
}
jobScheduled = true;
const cronString = common.replaceCronNames(cronTime);
param.onTick = async (context, onComplete) => {
return core.withMonitor(
monitorSlug,
async () => {
try {
await onTick(context, onComplete);
} catch (e) {
core.captureException(e, {
mechanism: {
handled: false,
type: 'auto.function.cron.instrumentCron',
},
});
throw e;
}
},
{
schedule: { type: 'crontab', value: cronString },
timezone: timeZone || undefined,
},
);
};
return target.from(param);
};
} else {
return target[prop];
}
},
});
}
exports.instrumentCron = instrumentCron;
//# sourceMappingURL=cron.js.map