fix(deps): update dependency node-cron to v4 (#3075)

Co-authored-by: Manuel <30572287+manuel-rw@users.noreply.github.com>
This commit is contained in:
homarr-renovate[bot]
2025-05-23 22:20:47 +02:00
committed by GitHub
parent 2afa9b6727
commit 109f9e7979
5 changed files with 21 additions and 23 deletions

View File

@@ -7,6 +7,6 @@ import { cronJobRunnerChannel } from ".";
*/ */
export const registerCronJobRunner = () => { export const registerCronJobRunner = () => {
cronJobRunnerChannel.subscribe((jobName) => { cronJobRunnerChannel.subscribe((jobName) => {
jobGroup.runManually(jobName); void jobGroup.runManuallyAsync(jobName);
}); });
}; };

View File

@@ -25,7 +25,7 @@
"prettier": "@homarr/prettier-config", "prettier": "@homarr/prettier-config",
"dependencies": { "dependencies": {
"@homarr/common": "workspace:^0.1.0", "@homarr/common": "workspace:^0.1.0",
"node-cron": "^3.0.3" "node-cron": "^4.0.7"
}, },
"devDependencies": { "devDependencies": {
"@homarr/eslint-config": "workspace:^0.2.0", "@homarr/eslint-config": "workspace:^0.2.0",

View File

@@ -1,5 +1,6 @@
import { AxiosError } from "axios"; import { AxiosError } from "axios";
import cron from "node-cron"; import type { ScheduledTask } from "node-cron";
import { schedule, validate } from "node-cron";
import { Stopwatch } from "@homarr/common"; import { Stopwatch } from "@homarr/common";
import type { MaybePromise } from "@homarr/common/types"; import type { MaybePromise } from "@homarr/common/types";
@@ -64,12 +65,11 @@ const createCallback = <TAllowedNames extends string, TName extends TAllowedName
/** /**
* We are not using the runOnInit method as we want to run the job only once we start the cron job schedule manually. * We are not using the runOnInit method as we want to run the job only once we start the cron job schedule manually.
* 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. * 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.
*/ */
let scheduledTask: cron.ScheduledTask | null = null; let scheduledTask: ScheduledTask | null = null;
if (cronExpression !== "never") { if (cronExpression !== "never") {
scheduledTask = cron.schedule(cronExpression, () => void catchingCallbackAsync(), { scheduledTask = schedule(cronExpression, () => void catchingCallbackAsync(), {
scheduled: false,
name, name,
timezone: creatorOptions.timezone, timezone: creatorOptions.timezone,
}); });
@@ -110,7 +110,7 @@ export const createCronJobCreator = <TAllowedNames extends string = string>(
options: CreateCronJobOptions = { runOnStart: false }, options: CreateCronJobOptions = { runOnStart: false },
) => { ) => {
creatorOptions.logger.logDebug(`Validating cron expression '${cronExpression}' for job: ${name}`); creatorOptions.logger.logDebug(`Validating cron expression '${cronExpression}' for job: ${name}`);
if (cronExpression !== "never" && !cron.validate(cronExpression)) { if (cronExpression !== "never" && !validate(cronExpression)) {
throw new Error(`Invalid cron expression '${cronExpression}' for job '${name}'`); throw new Error(`Invalid cron expression '${cronExpression}' for job '${name}'`);
} }
creatorOptions.logger.logDebug(`Cron job expression '${cronExpression}' for job ${name} is valid`); creatorOptions.logger.logDebug(`Cron job expression '${cronExpression}' for job ${name} is valid`);

View File

@@ -34,33 +34,33 @@ export const createJobGroupCreator = <TAllowedNames extends string = string>(
options.logger.logInfo(`Starting schedule cron job ${job.name}.`); options.logger.logInfo(`Starting schedule cron job ${job.name}.`);
await job.onStartAsync(); await job.onStartAsync();
job.scheduledTask?.start(); await job.scheduledTask?.start();
}, },
startAllAsync: async () => { startAllAsync: async () => {
for (const job of jobRegistry.values()) { for (const job of jobRegistry.values()) {
options.logger.logInfo(`Starting schedule of cron job ${job.name}.`); options.logger.logInfo(`Starting schedule of cron job ${job.name}.`);
await job.onStartAsync(); await job.onStartAsync();
job.scheduledTask?.start(); await job.scheduledTask?.start();
} }
}, },
runManually: (name: keyof TJobs) => { runManuallyAsync: async (name: keyof TJobs) => {
const job = jobRegistry.get(name as string); const job = jobRegistry.get(name as string);
if (!job) return; if (!job) return;
options.logger.logInfo(`Running schedule cron job ${job.name} manually.`); options.logger.logInfo(`Running schedule cron job ${job.name} manually.`);
job.scheduledTask?.now(); await job.scheduledTask?.execute();
}, },
stop: (name: keyof TJobs) => { stopAsync: async (name: keyof TJobs) => {
const job = jobRegistry.get(name as string); const job = jobRegistry.get(name as string);
if (!job) return; if (!job) return;
options.logger.logInfo(`Stopping schedule cron job ${job.name}.`); options.logger.logInfo(`Stopping schedule cron job ${job.name}.`);
job.scheduledTask?.stop(); await job.scheduledTask?.stop();
}, },
stopAll: () => { stopAllAsync: async () => {
for (const job of jobRegistry.values()) { for (const job of jobRegistry.values()) {
options.logger.logInfo(`Stopping schedule cron job ${job.name}.`); options.logger.logInfo(`Stopping schedule cron job ${job.name}.`);
job.scheduledTask?.stop(); await job.scheduledTask?.stop();
} }
}, },
getJobRegistry() { getJobRegistry() {

12
pnpm-lock.yaml generated
View File

@@ -996,8 +996,8 @@ importers:
specifier: workspace:^0.1.0 specifier: workspace:^0.1.0
version: link:../common version: link:../common
node-cron: node-cron:
specifier: ^3.0.3 specifier: ^4.0.7
version: 3.0.3 version: 4.0.7
devDependencies: devDependencies:
'@homarr/eslint-config': '@homarr/eslint-config':
specifier: workspace:^0.2.0 specifier: workspace:^0.2.0
@@ -8100,8 +8100,8 @@ packages:
resolution: {integrity: sha512-8VOpLHFrOQlAH+qA0ZzuGRlALRA6/LVh8QJldbrC4DY0hXoMP0l4Acq8TzFC018HztWiRqyCEj2aTWY2UvnJUg==} resolution: {integrity: sha512-8VOpLHFrOQlAH+qA0ZzuGRlALRA6/LVh8QJldbrC4DY0hXoMP0l4Acq8TzFC018HztWiRqyCEj2aTWY2UvnJUg==}
engines: {node: ^18 || ^20 || >= 21} engines: {node: ^18 || ^20 || >= 21}
node-cron@3.0.3: node-cron@4.0.7:
resolution: {integrity: sha512-dOal67//nohNgYWb+nWmg5dkFdIwDm8EpeGYMekPMrngV3637lqnX0lbUcCtgibHTz6SEz7DAIjKvKDFYCnO1A==} resolution: {integrity: sha512-A37UUDpxRT/kWanELr/oMayCWQFk9Zx9BEUoXrAKuKwKzH4XuAX+vMixMBPkgZBkADgJwXv91w5cMRTNSVP/mA==}
engines: {node: '>=6.0.0'} engines: {node: '>=6.0.0'}
node-domexception@1.0.0: node-domexception@1.0.0:
@@ -17209,9 +17209,7 @@ snapshots:
node-addon-api@8.3.0: {} node-addon-api@8.3.0: {}
node-cron@3.0.3: node-cron@4.0.7: {}
dependencies:
uuid: 8.3.2
node-domexception@1.0.0: {} node-domexception@1.0.0: {}