refactor: native repository healthcheck

This commit is contained in:
Nicolas Meienberger
2025-11-28 08:20:06 +01:00
parent 803eb1cd76
commit 8e90c4ace1

View File

@@ -249,21 +249,18 @@ const checkHealth = async (repositoryId: string) => {
throw new NotFoundError("Repository not found"); throw new NotFoundError("Repository not found");
} }
const { error, status } = await restic const { hasErrors, error } = await restic.check(repository.config, { readData: true });
.snapshots(repository.config)
.then(() => ({ error: null, status: "healthy" as const }))
.catch((error) => ({ error: toMessage(error), status: "error" as const }));
await db await db
.update(repositoriesTable) .update(repositoriesTable)
.set({ .set({
status, status: hasErrors ? "error" : "healthy",
lastChecked: Date.now(), lastChecked: Date.now(),
lastError: error, lastError: error,
}) })
.where(eq(repositoriesTable.id, repository.id)); .where(eq(repositoriesTable.id, repository.id));
return { status, lastError: error }; return { lastError: error };
}; };
const doctorRepository = async (name: string) => { const doctorRepository = async (name: string) => {