zerobyte/app/server/jobs/healthchecks.ts
Nico 332e5bffda
refactor: extract restic in core package (#651)
* refactor: extract restic in core package

* chore: add turbo task runner

* refactor: split server utils

* chore: simplify withDeps signature and fix non-null assertion
2026-03-11 21:56:07 +01:00

32 lines
977 B
TypeScript

import { Job } from "../core/scheduler";
import { volumeService } from "../modules/volumes/volume.service";
import { logger } from "@zerobyte/core/node";
import { db } from "../db/db";
import { withContext } from "../core/request-context";
export class VolumeHealthCheckJob extends Job {
async run() {
logger.debug("Running health check for all volumes...");
const volumes = await db.query.volumesTable.findMany({
where: {
OR: [{ status: "mounted" }, { status: "error" }],
},
});
for (const volume of volumes) {
try {
await withContext({ organizationId: volume.organizationId }, async () => {
const { status } = await volumeService.checkHealth(volume.shortId);
if (status === "error" && volume.autoRemount) {
await volumeService.mountVolume(volume.shortId);
}
});
} catch (error) {
logger.error(`Health check failed for volume ${volume.name}:`, error);
}
}
return { done: true, timestamp: new Date() };
}
}