feat: docker widget (#2288)
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>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { analyticsJob } from "./jobs/analytics";
|
||||
import { dockerContainersJob } from "./jobs/docker";
|
||||
import { iconsUpdaterJob } from "./jobs/icons-updater";
|
||||
import { dnsHoleJob } from "./jobs/integrations/dns-hole";
|
||||
import { downloadsJob } from "./jobs/integrations/downloads";
|
||||
@@ -35,6 +36,7 @@ export const jobGroup = createCronJobGroup({
|
||||
updateChecker: updateCheckerJob,
|
||||
mediaTranscoding: mediaTranscodingJob,
|
||||
minecraftServerStatus: minecraftServerStatusJob,
|
||||
dockerContainers: dockerContainersJob,
|
||||
networkController: networkControllerJob,
|
||||
});
|
||||
|
||||
|
||||
28
packages/cron-jobs/src/jobs/docker.ts
Normal file
28
packages/cron-jobs/src/jobs/docker.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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 });
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user