Archived
remove controller service lock
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { createServer } from "node:http";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { AgentStore } from "../../adapters/database/store.js";
|
||||
@@ -25,9 +24,6 @@ async function main(): Promise<void> {
|
||||
const store = new AgentStore(
|
||||
process.env.AGENT_DB_PATH || "/var/lib/gitea-agent/agent.db",
|
||||
);
|
||||
const owner = `controller-${randomUUID()}`;
|
||||
if (!store.acquireServiceLock("controller", owner, 30_000))
|
||||
throw new Error("Another controller owns the service lock");
|
||||
store.recoverControllerWork();
|
||||
store.purgeDeliveries(Date.now() - 7 * 24 * 60 * 60_000);
|
||||
const shutdown = new AbortController();
|
||||
@@ -93,13 +89,11 @@ async function main(): Promise<void> {
|
||||
}
|
||||
};
|
||||
const pumpTimer = setInterval(pump, 250);
|
||||
const lockTimer = setInterval(() => renewLock(store, owner), 5_000);
|
||||
const retentionTimer = setInterval(
|
||||
() => store.purgeDeliveries(Date.now() - 7 * 24 * 60 * 60_000),
|
||||
60 * 60_000,
|
||||
);
|
||||
pumpTimer.unref();
|
||||
lockTimer.unref();
|
||||
retentionTimer.unref();
|
||||
|
||||
const server = createServer((request, response) => {
|
||||
@@ -141,7 +135,6 @@ async function main(): Promise<void> {
|
||||
if (stopping) return;
|
||||
stopping = true;
|
||||
clearInterval(pumpTimer);
|
||||
clearInterval(lockTimer);
|
||||
clearInterval(retentionTimer);
|
||||
server.close(() => resolve());
|
||||
shutdown.abort(new Error("Controller is shutting down"));
|
||||
@@ -153,24 +146,9 @@ async function main(): Promise<void> {
|
||||
delivering?.catch(() => undefined),
|
||||
publishing?.catch(() => undefined),
|
||||
]);
|
||||
store.releaseServiceLock("controller", owner);
|
||||
store.close();
|
||||
}
|
||||
|
||||
function renewLock(store: AgentStore, owner: string): void {
|
||||
try {
|
||||
if (!store.renewServiceLock("controller", owner, 30_000))
|
||||
process.kill(process.pid, "SIGTERM");
|
||||
} catch (error) {
|
||||
console.error(
|
||||
log("error", "Controller lock renewal failed", {
|
||||
error: safeFailure(error),
|
||||
}),
|
||||
);
|
||||
process.kill(process.pid, "SIGTERM");
|
||||
}
|
||||
}
|
||||
|
||||
function parsePort(value: string): number {
|
||||
const port = Number(value);
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65_535)
|
||||
|
||||
Reference in New Issue
Block a user