nestjs-temporal-core
Version:
Complete NestJS integration for Temporal.io with auto-discovery, declarative scheduling, enhanced monitoring, and enterprise-ready features
44 lines • 1.72 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Interval = exports.Cron = exports.Scheduled = void 0;
const common_1 = require("@nestjs/common");
const constants_1 = require("../constants");
const utils_1 = require("../utils");
const Scheduled = (options) => {
return (_target, _propertyKey, descriptor) => {
if (!options.scheduleId) {
throw new Error('@Scheduled requires scheduleId');
}
if (!options.cron && !options.interval) {
throw new Error('@Scheduled requires either cron or interval');
}
if (options.cron && options.interval) {
throw new Error('@Scheduled cannot have both cron and interval');
}
if (options.cron && !(0, utils_1.isValidCronExpression)(options.cron)) {
throw new Error(`Invalid cron expression: ${options.cron}`);
}
if (options.interval && !(0, utils_1.isValidIntervalExpression)(options.interval)) {
throw new Error(`Invalid interval expression: ${options.interval}`);
}
Reflect.defineMetadata(constants_1.TEMPORAL_SCHEDULED_WORKFLOW, options, descriptor.value);
(0, common_1.SetMetadata)(constants_1.TEMPORAL_SCHEDULED_WORKFLOW, options)(descriptor.value);
return descriptor;
};
};
exports.Scheduled = Scheduled;
const Cron = (cronExpression, options) => {
return (0, exports.Scheduled)({
...options,
cron: cronExpression,
});
};
exports.Cron = Cron;
const Interval = (interval, options) => {
return (0, exports.Scheduled)({
...options,
interval,
});
};
exports.Interval = Interval;
//# sourceMappingURL=scheduling.decorator.js.map
;