mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-18 05:47:31 -04:00
* feat(agent): add standalone agent runtime * fix(agent): add Bun and DOM types to agent tsconfig * refactor: wrap backup error in a tagged effect error * feat(controller): add agent manager and session handling * feat(backups): execute backups through the agent * fix(agent): harden disconnect and send-failure handling * fix: rebase conflicts * test: simplify mocks * refactor: split agent runtime state * fix(backup): keep old path when agent is disabled * fix: pr feedbacks
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import type { ChildProcess } from "node:child_process";
|
|
import type { ResticBackupOutputDto } from "@zerobyte/core/restic";
|
|
import type { BackupProgressPayload } from "@zerobyte/contracts/agent-protocol";
|
|
import type { AgentManagerRuntime } from "../controller/server";
|
|
|
|
export type BackupExecutionProgress = BackupProgressPayload["progress"];
|
|
export type BackupExecutionResult =
|
|
| { status: "unavailable"; error: Error }
|
|
| { status: "completed"; exitCode: number; result: ResticBackupOutputDto | null; warningDetails: string | null }
|
|
| { status: "failed"; error: string }
|
|
| { status: "cancelled"; message?: string };
|
|
|
|
type ActiveBackupRun = {
|
|
scheduleId: number;
|
|
jobId: string;
|
|
scheduleShortId: string;
|
|
onProgress: (progress: BackupExecutionProgress) => void;
|
|
resolve: (result: BackupExecutionResult) => void;
|
|
cancellationRequested: boolean;
|
|
};
|
|
|
|
export type AgentRuntimeState = {
|
|
agentManager: AgentManagerRuntime | null;
|
|
localAgent: ChildProcess | null;
|
|
isStoppingLocalAgent: boolean;
|
|
localAgentRestartTimeout: ReturnType<typeof setTimeout> | null;
|
|
activeBackupsByScheduleId: Map<number, ActiveBackupRun>;
|
|
activeBackupScheduleIdsByJobId: Map<string, number>;
|
|
};
|
|
|
|
export const createAgentRuntimeState = (): AgentRuntimeState => ({
|
|
agentManager: null,
|
|
localAgent: null,
|
|
isStoppingLocalAgent: false,
|
|
localAgentRestartTimeout: null,
|
|
activeBackupsByScheduleId: new Map(),
|
|
activeBackupScheduleIdsByJobId: new Map(),
|
|
});
|