fix: ping urls are not reset when restarting (#924)
This commit is contained in:
@@ -16,6 +16,7 @@ export interface CreateCronJobCreatorOptions<TAllowedNames extends string> {
|
|||||||
|
|
||||||
interface CreateCronJobOptions {
|
interface CreateCronJobOptions {
|
||||||
runOnStart?: boolean;
|
runOnStart?: boolean;
|
||||||
|
beforeStart?: () => MaybePromise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createCallback = <TAllowedNames extends string, TName extends TAllowedNames>(
|
const createCallback = <TAllowedNames extends string, TName extends TAllowedNames>(
|
||||||
@@ -62,6 +63,11 @@ const createCallback = <TAllowedNames extends string, TName extends TAllowedName
|
|||||||
cronExpression,
|
cronExpression,
|
||||||
scheduledTask,
|
scheduledTask,
|
||||||
async onStartAsync() {
|
async onStartAsync() {
|
||||||
|
if (options.beforeStart) {
|
||||||
|
creatorOptions.logger.logDebug(`Running beforeStart for job: ${name}`);
|
||||||
|
await options.beforeStart();
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.runOnStart) return;
|
if (!options.runOnStart) return;
|
||||||
|
|
||||||
creatorOptions.logger.logDebug(`The cron job '${name}' is running because runOnStart is set to true`);
|
creatorOptions.logger.logDebug(`The cron job '${name}' is running because runOnStart is set to true`);
|
||||||
|
|||||||
@@ -5,7 +5,14 @@ import { pingChannel, pingUrlChannel } from "@homarr/redis";
|
|||||||
|
|
||||||
import { createCronJob } from "../lib";
|
import { createCronJob } from "../lib";
|
||||||
|
|
||||||
export const pingJob = createCronJob("ping", EVERY_MINUTE).withCallback(async () => {
|
const resetPreviousUrlsAsync = async () => {
|
||||||
|
await pingUrlChannel.clearAsync();
|
||||||
|
logger.info("Cleared previous ping urls");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const pingJob = createCronJob("ping", EVERY_MINUTE, {
|
||||||
|
beforeStart: resetPreviousUrlsAsync,
|
||||||
|
}).withCallback(async () => {
|
||||||
const urls = await pingUrlChannel.getAllAsync();
|
const urls = await pingUrlChannel.getAllAsync();
|
||||||
|
|
||||||
for (const url of new Set(urls)) {
|
for (const url of new Set(urls)) {
|
||||||
|
|||||||
@@ -77,6 +77,12 @@ export const createListChannel = <TItem>(name: string) => {
|
|||||||
removeAsync: async (item: TItem) => {
|
removeAsync: async (item: TItem) => {
|
||||||
await getSetClient.lrem(listChannelName, 0, superjson.stringify(item));
|
await getSetClient.lrem(listChannelName, 0, superjson.stringify(item));
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Clear all items from the channels list
|
||||||
|
*/
|
||||||
|
clearAsync: async () => {
|
||||||
|
await getSetClient.del(listChannelName);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Add an item to the channels list
|
* Add an item to the channels list
|
||||||
* @param item item to add
|
* @param item item to add
|
||||||
|
|||||||
Reference in New Issue
Block a user