Skip to content

Commit 109f9e7

Browse files
fix(deps): update dependency node-cron to v4 (#3075)
Co-authored-by: Manuel <[email protected]>
1 parent 2afa9b6 commit 109f9e7

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

packages/cron-job-runner/src/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import { cronJobRunnerChannel } from ".";
77
*/
88
export const registerCronJobRunner = () => {
99
cronJobRunnerChannel.subscribe((jobName) => {
10-
jobGroup.runManually(jobName);
10+
void jobGroup.runManuallyAsync(jobName);
1111
});
1212
};

packages/cron-jobs-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"prettier": "@homarr/prettier-config",
2626
"dependencies": {
2727
"@homarr/common": "workspace:^0.1.0",
28-
"node-cron": "^3.0.3"
28+
"node-cron": "^4.0.7"
2929
},
3030
"devDependencies": {
3131
"@homarr/eslint-config": "workspace:^0.2.0",

packages/cron-jobs-core/src/creator.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AxiosError } from "axios";
2-
import cron from "node-cron";
2+
import type { ScheduledTask } from "node-cron";
3+
import { schedule, validate } from "node-cron";
34

45
import { Stopwatch } from "@homarr/common";
56
import type { MaybePromise } from "@homarr/common/types";
@@ -64,12 +65,11 @@ const createCallback = <TAllowedNames extends string, TName extends TAllowedName
6465

6566
/**
6667
* We are not using the runOnInit method as we want to run the job only once we start the cron job schedule manually.
67-
* This allows us to always run it once we start it. Additionally it will not run the callback if only the cron job file is imported.
68+
* This allows us to always run it once we start it. Additionally, it will not run the callback if only the cron job file is imported.
6869
*/
69-
let scheduledTask: cron.ScheduledTask | null = null;
70+
let scheduledTask: ScheduledTask | null = null;
7071
if (cronExpression !== "never") {
71-
scheduledTask = cron.schedule(cronExpression, () => void catchingCallbackAsync(), {
72-
scheduled: false,
72+
scheduledTask = schedule(cronExpression, () => void catchingCallbackAsync(), {
7373
name,
7474
timezone: creatorOptions.timezone,
7575
});
@@ -110,7 +110,7 @@ export const createCronJobCreator = <TAllowedNames extends string = string>(
110110
options: CreateCronJobOptions = { runOnStart: false },
111111
) => {
112112
creatorOptions.logger.logDebug(`Validating cron expression '${cronExpression}' for job: ${name}`);
113-
if (cronExpression !== "never" && !cron.validate(cronExpression)) {
113+
if (cronExpression !== "never" && !validate(cronExpression)) {
114114
throw new Error(`Invalid cron expression '${cronExpression}' for job '${name}'`);
115115
}
116116
creatorOptions.logger.logDebug(`Cron job expression '${cronExpression}' for job ${name} is valid`);

packages/cron-jobs-core/src/group.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,33 @@ export const createJobGroupCreator = <TAllowedNames extends string = string>(
3434

3535
options.logger.logInfo(`Starting schedule cron job ${job.name}.`);
3636
await job.onStartAsync();
37-
job.scheduledTask?.start();
37+
await job.scheduledTask?.start();
3838
},
3939
startAllAsync: async () => {
4040
for (const job of jobRegistry.values()) {
4141
options.logger.logInfo(`Starting schedule of cron job ${job.name}.`);
4242
await job.onStartAsync();
43-
job.scheduledTask?.start();
43+
await job.scheduledTask?.start();
4444
}
4545
},
46-
runManually: (name: keyof TJobs) => {
46+
runManuallyAsync: async (name: keyof TJobs) => {
4747
const job = jobRegistry.get(name as string);
4848
if (!job) return;
4949

5050
options.logger.logInfo(`Running schedule cron job ${job.name} manually.`);
51-
job.scheduledTask?.now();
51+
await job.scheduledTask?.execute();
5252
},
53-
stop: (name: keyof TJobs) => {
53+
stopAsync: async (name: keyof TJobs) => {
5454
const job = jobRegistry.get(name as string);
5555
if (!job) return;
5656

5757
options.logger.logInfo(`Stopping schedule cron job ${job.name}.`);
58-
job.scheduledTask?.stop();
58+
await job.scheduledTask?.stop();
5959
},
60-
stopAll: () => {
60+
stopAllAsync: async () => {
6161
for (const job of jobRegistry.values()) {
6262
options.logger.logInfo(`Stopping schedule cron job ${job.name}.`);
63-
job.scheduledTask?.stop();
63+
await job.scheduledTask?.stop();
6464
}
6565
},
6666
getJobRegistry() {

pnpm-lock.yaml

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)