mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-19 14:28:54 -04:00
refactor: separate healthcheck and auto remount in two separate jobs
This commit is contained in:
@@ -4,10 +4,6 @@ export const REPOSITORY_BASE = "/var/lib/zerobyte/repositories";
|
||||
export const DATABASE_URL = "/var/lib/zerobyte/data/ironmount.db";
|
||||
export const RESTIC_PASS_FILE = "/var/lib/zerobyte/data/restic.pass";
|
||||
|
||||
export const DEFAULT_EXCLUDES = [
|
||||
DATABASE_URL,
|
||||
RESTIC_PASS_FILE,
|
||||
"/var/lib/zerobyte/repositories/**", // To avoid circular backups
|
||||
];
|
||||
export const DEFAULT_EXCLUDES = [DATABASE_URL, RESTIC_PASS_FILE, REPOSITORY_BASE];
|
||||
|
||||
export const REQUIRED_MIGRATIONS = ["v0.14.0"];
|
||||
|
||||
24
app/server/jobs/auto-remount.ts
Normal file
24
app/server/jobs/auto-remount.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Job } from "../core/scheduler";
|
||||
import { volumeService } from "../modules/volumes/volume.service";
|
||||
import { logger } from "../utils/logger";
|
||||
import { db } from "../db/db";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { volumesTable } from "../db/schema";
|
||||
|
||||
export class VolumeAutoRemountJob extends Job {
|
||||
async run() {
|
||||
logger.debug("Running auto-remount for all errored volumes...");
|
||||
|
||||
const volumes = await db.query.volumesTable.findMany({
|
||||
where: eq(volumesTable.status, "error"),
|
||||
});
|
||||
|
||||
for (const volume of volumes) {
|
||||
if (volume.autoRemount) {
|
||||
await volumeService.mountVolume(volume.name);
|
||||
}
|
||||
}
|
||||
|
||||
return { done: true, timestamp: new Date() };
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import { logger } from "../utils/logger";
|
||||
import { db } from "../db/db";
|
||||
import { eq, or } from "drizzle-orm";
|
||||
import { repositoriesTable } from "../db/schema";
|
||||
import { repoMutex } from "../core/repository-mutex";
|
||||
|
||||
export class RepositoryHealthCheckJob extends Job {
|
||||
async run() {
|
||||
@@ -15,11 +14,6 @@ export class RepositoryHealthCheckJob extends Job {
|
||||
});
|
||||
|
||||
for (const repository of repositories) {
|
||||
if (repoMutex.isLocked(repository.id)) {
|
||||
logger.debug(`Skipping health check for repository ${repository.name}: currently locked`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await repositoriesService.checkHealth(repository.id);
|
||||
} catch (error) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { BackupExecutionJob } from "../../jobs/backup-execution";
|
||||
import { CleanupSessionsJob } from "../../jobs/cleanup-sessions";
|
||||
import { repositoriesService } from "../repositories/repositories.service";
|
||||
import { notificationsService } from "../notifications/notifications.service";
|
||||
import { VolumeAutoRemountJob } from "~/server/jobs/auto-remount";
|
||||
|
||||
const ensureLatestConfigurationSchema = async () => {
|
||||
const volumes = await db.query.volumesTable.findMany({});
|
||||
@@ -67,4 +68,5 @@ export const startup = async () => {
|
||||
Scheduler.build(RepositoryHealthCheckJob).schedule("50 12 * * *");
|
||||
Scheduler.build(BackupExecutionJob).schedule("* * * * *");
|
||||
Scheduler.build(CleanupSessionsJob).schedule("0 0 * * *");
|
||||
Scheduler.build(VolumeAutoRemountJob).schedule("*/5 * * * *");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user