zerobyte/app/server/jobs/healthchecks.ts
Nico 63b08a4b71
feat(backups): ensure volume readiness before backup (#815)
* feat(backups): ensure volume readiness before backup

Backup preflight checks were relying on a db cached status. Now a real
volume healthcheck is performed before backing up. Closes #811 #695

* chore: fix ci
2026-04-20 21:18:29 +02:00

29 lines
851 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 () => {
await volumeService.ensureHealthyVolume(volume.shortId);
});
} catch (error) {
logger.error(`Health check failed for volume ${volume.name}:`, error);
}
}
return { done: true, timestamp: new Date() };
}
}