Skip to content

Commit

Permalink
fix(deps): update dependency cron-parser to v5 (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
renovate[bot] authored and e-adrien committed Feb 14, 2025
1 parent aaa3282 commit 223d0f3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dependencies": {
"@lesjoursfr/date": "^1.0.2",
"@lesjoursfr/human-interval": "^1.0.2",
"cron-parser": "^4.9.0",
"cron-parser": "^5.0.0",
"debug": "^4.4.0",
"luxon": "^3.5.0",
"mongodb": "~6.13.0"
Expand Down
8 changes: 3 additions & 5 deletions src/utils/next-run-at.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import date from "@lesjoursfr/date";
import humanInterval from "@lesjoursfr/human-interval";
import cronParser from "cron-parser";
import { CronExpressionParser } from "cron-parser";
import debug from "debug";
import { DateTime } from "luxon";
import type { IJobParameters } from "../interfaces";
import { isValidDate } from "./is-valid-date";

const { parseExpression } = cronParser;

const log = debug("agenda:nextRunAt");

const dateForTimezone = (timezoneDate: Date, timezone?: string): DateTime =>
Expand Down Expand Up @@ -38,12 +36,12 @@ export const computeFromInterval = (attrs: IJobParameters<any>): Date => {
let error;
if (typeof attrs.repeatInterval === "string") {
try {
let cronTime = parseExpression(attrs.repeatInterval, cronOptions);
let cronTime = CronExpressionParser.parse(attrs.repeatInterval, cronOptions);
let nextDate = cronTime.next().toDate();
if (nextDate.valueOf() === lastRun.valueOf() || nextDate.valueOf() <= previousNextRunAt.valueOf()) {
// Handle cronTime giving back the same date for the next run time
cronOptions.currentDate = new Date(lastRun.valueOf() + 1000);
cronTime = parseExpression(attrs.repeatInterval, cronOptions);
cronTime = CronExpressionParser.parse(attrs.repeatInterval, cronOptions);
nextDate = cronTime.next().toDate();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/job.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ describe("Job", function () {
it("fails the job", function () {
strictEqual(
job.attrs.failReason,
'failed to calculate nextRunAt due to invalid repeat interval (asd): Error: Validation error, cannot resolve alias "asd"'
"failed to calculate nextRunAt due to invalid repeat interval (asd): AssertionError [ERR_ASSERTION]: Constraint error, got value 0 expected range 1-12"
);
});
});
Expand Down

0 comments on commit 223d0f3

Please sign in to comment.