1 parent
6e23f1533b
commit
419325db12
52 files changed
+1329
-110
No files matched your search
+16
-3
@@ -8,6 +8,9 @@ import { cleanupExpired, listQueuedJobIds, readJobForWorker, recoverStaleJobs, r
|
||||
import { asJson } from "../src/server/spreadsheet-adapter/db-utils";
|
||||
import type { JobProgress, RequestContext, Role } from "../src/domain/spreadsheet-adapter/types";
|
||||
|
||||
import { assertProductionEnv } from "../src/config/env";
|
||||
|
||||
assertProductionEnv(process.env);
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
if (!databaseUrl && process.env.NODE_ENV === "production") {
|
||||
throw new Error("DATABASE_URL é obrigatório para o worker.");
|
||||
@@ -17,9 +20,19 @@ await migrate(db);
|
||||
const deps = { db, storage: createStorage(), coordinator: createCoordinator() };
|
||||
|
||||
async function tick() {
|
||||
await recoverStaleJobs(deps);
|
||||
await cleanupExpired(deps);
|
||||
for (const jobId of await listQueuedJobIds(deps)) {
|
||||
await recoverStaleJobs(deps).catch((error) => {
|
||||
console.error("worker", error instanceof Error ? error.name : "error");
|
||||
});
|
||||
await cleanupExpired(deps).catch((error) => {
|
||||
console.error("worker", "cleanup", error instanceof Error ? error.name : "error");
|
||||
});
|
||||
const queued = new Set(await listQueuedJobIds(deps));
|
||||
for (let index = 0; index < 20; index += 1) {
|
||||
const jobId = await deps.coordinator.dequeue().catch(() => null);
|
||||
if (!jobId) break;
|
||||
queued.add(jobId);
|
||||
}
|
||||
for (const jobId of queued) {
|
||||
const rows = await readJobForWorker(deps, jobId);
|
||||
const row = rows[0];
|
||||
if (!row) continue;
|
||||
|
||||
Reference in new issue
Block a user