chore: pr feedback
This commit is contained in:
parent
1b5ae2b3cc
commit
629dbf3ddb
3 changed files with 6 additions and 42 deletions
|
|
@ -4,7 +4,6 @@ import { createTestSession, getAuthHeaders } from "~/test/helpers/auth";
|
|||
import { createTestVolume } from "~/test/helpers/volume";
|
||||
import { createTestRepository } from "~/test/helpers/repository";
|
||||
import { createTestBackupSchedule } from "~/test/helpers/backup";
|
||||
import { cache, cacheKeys } from "~/server/utils/cache";
|
||||
|
||||
const app = createApp();
|
||||
|
||||
|
|
@ -82,47 +81,6 @@ describe("backups security", () => {
|
|||
});
|
||||
|
||||
describe("input validation", () => {
|
||||
test("should return cached progress for a running backup", async () => {
|
||||
const { headers, organizationId } = await createTestSession();
|
||||
const volume = await createTestVolume({ organizationId });
|
||||
const repository = await createTestRepository({ organizationId });
|
||||
const schedule = await createTestBackupSchedule({
|
||||
organizationId,
|
||||
volumeId: volume.id,
|
||||
repositoryId: repository.id,
|
||||
});
|
||||
|
||||
cache.set(cacheKeys.backup.progress(schedule.id), {
|
||||
scheduleId: schedule.shortId,
|
||||
volumeName: volume.name,
|
||||
repositoryName: repository.name,
|
||||
message_type: "status",
|
||||
seconds_elapsed: 12,
|
||||
seconds_remaining: 24,
|
||||
percent_done: 0.5,
|
||||
total_files: 100,
|
||||
files_done: 50,
|
||||
total_bytes: 1024,
|
||||
bytes_done: 512,
|
||||
current_files: ["/mnt/data/file.txt"],
|
||||
});
|
||||
|
||||
const res = await app.request(`/api/v1/backups/${schedule.shortId}/progress`, {
|
||||
headers,
|
||||
});
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
const body = await res.json();
|
||||
expect(body).toMatchObject({
|
||||
scheduleId: schedule.shortId,
|
||||
percent_done: 0.5,
|
||||
files_done: 50,
|
||||
current_files: ["/mnt/data/file.txt"],
|
||||
});
|
||||
|
||||
cache.del(cacheKeys.backup.progress(schedule.id));
|
||||
});
|
||||
|
||||
test("should return a schedule when queried by short id", async () => {
|
||||
const { headers, organizationId } = await createTestSession();
|
||||
const volume = await createTestVolume({ organizationId });
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import { requireAuth } from "../auth/auth.middleware";
|
|||
import { backupsExecutionService } from "./backups.execution";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { asShortId } from "~/server/utils/branded";
|
||||
import { cache, cacheKeys } from "~/server/utils/cache";
|
||||
|
||||
export const backupScheduleController = new Hono()
|
||||
.use(requireAuth)
|
||||
|
|
@ -167,6 +168,10 @@ export const backupScheduleController = new Hono()
|
|||
.get("/:shortId/progress", getBackupProgressDto, async (c) => {
|
||||
const shortId = asShortId(c.req.param("shortId"));
|
||||
const schedule = await backupsService.getScheduleByShortId(shortId);
|
||||
if (schedule.lastBackupStatus !== "in_progress") {
|
||||
cache.del(cacheKeys.backup.progress(schedule.id));
|
||||
return c.json<GetBackupProgressDto>(null, 200);
|
||||
}
|
||||
const progress = backupsExecutionService.getBackupProgress(schedule.id);
|
||||
|
||||
return c.json<GetBackupProgressDto>(progress ?? null, 200);
|
||||
|
|
|
|||
|
|
@ -268,6 +268,7 @@ const executeBackup = async (scheduleId: number, manual = false): Promise<void>
|
|||
}
|
||||
|
||||
const { context: ctx } = result;
|
||||
cache.del(cacheKeys.backup.progress(scheduleId));
|
||||
emitBackupStarted(ctx, scheduleId);
|
||||
|
||||
const nextBackupAt = calculateNextRun(ctx.schedule.cronExpression);
|
||||
|
|
|
|||
Loading…
Reference in a new issue