e1eda534da
Co-authored-by: Crowdin Homarr <190541745+homarr-crowdin[bot]@users.noreply.github.com> Co-authored-by: homarr-renovate[bot] <158783068+homarr-renovate[bot]@users.noreply.github.com> Co-authored-by: homarr-crowdin[bot] <190541745+homarr-crowdin[bot]@users.noreply.github.com> Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import SuperJSON from "superjson";
|
|
|
|
import { EVERY_MINUTE } from "@homarr/cron-jobs-core/expressions";
|
|
import { db, eq } from "@homarr/db";
|
|
import { items } from "@homarr/db/schema";
|
|
import { logger } from "@homarr/log";
|
|
import { dockerContainersRequestHandler } from "@homarr/request-handler/docker";
|
|
|
|
import type { WidgetComponentProps } from "../../../widgets";
|
|
import { createCronJob } from "../lib";
|
|
|
|
export const dockerContainersJob = createCronJob("dockerContainers", EVERY_MINUTE).withCallback(async () => {
|
|
const dockerItems = await db.query.items.findMany({
|
|
where: eq(items.kind, "dockerContainers"),
|
|
});
|
|
|
|
await Promise.allSettled(
|
|
dockerItems.map(async (item) => {
|
|
try {
|
|
const options = SuperJSON.parse<WidgetComponentProps<"dockerContainers">["options"]>(item.options);
|
|
const innerHandler = dockerContainersRequestHandler.handler(options);
|
|
await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: true });
|
|
} catch (error) {
|
|
logger.error("Failed to update Docker container status", { item, error });
|
|
}
|
|
}),
|
|
);
|
|
});
|