feat(tasktree): add GitHub disaster recovery backups
This commit is contained in:
@@ -3,9 +3,13 @@ import { NativeConnection, Worker } from "@temporalio/worker";
|
||||
import path from "node:path";
|
||||
|
||||
import { createTaskTreeActivities } from "../../internal/tasktree/activities.ts";
|
||||
import { startTaskTreeBackupScheduler } from "../../internal/tasktree/backup.ts";
|
||||
import { taskTreeRuntime } from "../../internal/tasktree/runtime.ts";
|
||||
|
||||
const runtime = taskTreeRuntime();
|
||||
const runtime = taskTreeRuntime({
|
||||
...process.env,
|
||||
TASKTREE_BACKUP_WORKTREE: process.env.TASKTREE_BACKUP_WORKTREE ?? ".state/tasktree/backup-repo-worker",
|
||||
});
|
||||
if (!runtime.temporalAddress) throw new Error("TASKTREE_TEMPORAL_ADDRESS is required");
|
||||
await runtime.store.ensureSchema();
|
||||
const connection = await NativeConnection.connect({ address: runtime.temporalAddress });
|
||||
@@ -17,13 +21,22 @@ const worker = await Worker.create({
|
||||
activities: createTaskTreeActivities(runtime.store)
|
||||
});
|
||||
const healthPort = Number.parseInt(process.env.TASKTREE_WORKER_HEALTH_PORT || "6674", 10);
|
||||
const backupScheduler = startTaskTreeBackupScheduler(runtime.backup, (result) => {
|
||||
process.stdout.write(`${JSON.stringify({ serviceId: "hwlab-tasktree-worker", ...result })}\n`);
|
||||
});
|
||||
const health = Bun.serve({
|
||||
hostname: process.env.TASKTREE_WORKER_HEALTH_HOST || "0.0.0.0",
|
||||
port: healthPort,
|
||||
fetch(request) {
|
||||
async fetch(request) {
|
||||
const pathname = new URL(request.url).pathname;
|
||||
if (pathname !== "/health/live" && pathname !== "/health/ready") return Response.json({ ok: false, error: "not_found" }, { status: 404 });
|
||||
return Response.json({ ok: true, serviceId: "hwlab-tasktree-worker", namespace: runtime.temporalNamespace, taskQueue: runtime.taskQueue });
|
||||
return Response.json({
|
||||
ok: true,
|
||||
serviceId: "hwlab-tasktree-worker",
|
||||
namespace: runtime.temporalNamespace,
|
||||
taskQueue: runtime.taskQueue,
|
||||
backup: await runtime.backup.status(),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -32,6 +45,7 @@ for (const signal of ["SIGINT", "SIGTERM"] as const) process.once(signal, () =>
|
||||
try {
|
||||
await worker.run();
|
||||
} finally {
|
||||
await backupScheduler.stop();
|
||||
health.stop(true);
|
||||
await connection.close();
|
||||
await runtime.store.close();
|
||||
|
||||
Reference in New Issue
Block a user