* refactor: add cron job core package * docs: add comments to cron validation types * chore(deps): move node-cron dependencies from tasks app to cron-jobs-core package * fix: runOnInit is not running on start and rather on job creation * fix: format issues * fix: build fails when using top level await in cjs * chore: update turbo gen package json typescript version to 5.5.2 * fix: format issue * fix: deepsource issues * chore: update turbo gen package json eslint version to 9.5.0 * chore: fix frozen lockfile and format
26 lines
826 B
TypeScript
26 lines
826 B
TypeScript
import { EVERY_MINUTE } from "@homarr/cron-jobs-core/expressions";
|
|
import { logger } from "@homarr/log";
|
|
import { sendPingRequestAsync } from "@homarr/ping";
|
|
import { pingChannel, pingUrlChannel } from "@homarr/redis";
|
|
|
|
import { createCronJob } from "~/lib/jobs";
|
|
|
|
export const pingJob = createCronJob("ping", EVERY_MINUTE).withCallback(async () => {
|
|
const urls = await pingUrlChannel.getAllAsync();
|
|
|
|
for (const url of new Set(urls)) {
|
|
const pingResult = await sendPingRequestAsync(url);
|
|
|
|
if ("statusCode" in pingResult) {
|
|
logger.debug(`executed ping for url ${url} with status code ${pingResult.statusCode}`);
|
|
} else {
|
|
logger.error(`Executing ping for url ${url} failed with error: ${pingResult.error}`);
|
|
}
|
|
|
|
await pingChannel.publishAsync({
|
|
url,
|
|
...pingResult,
|
|
});
|
|
}
|
|
});
|