- Tasks keyed by {taskType}-{repo}-{issue} for deduplication
- Duplicate requests (pending or running) are dropped
- Configurable concurrency via QUEUE_CONCURRENCY env (default 2)
- Workspace names now {taskType}-{repo}-{issue} for observability
- GET /queue endpoint shows pending/running tasks
- All handlers route through the queue instead of calling Coder directly
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
6062d1b518
commit
f23fb4e2e0
+14
-9
@@ -6,6 +6,7 @@ import cron from "node-cron";
|
||||
import { loadConfig } from "./config.js";
|
||||
import { CoderClient } from "./services/coder.js";
|
||||
import { GiteaClient } from "./services/gitea.js";
|
||||
import { TaskQueue } from "./queue.js";
|
||||
|
||||
import { issueTriage } from "./handlers/issue-triage.js";
|
||||
import { issueLabel } from "./handlers/issue-label.js";
|
||||
@@ -23,26 +24,30 @@ const config = loadConfig();
|
||||
const coderClient = new CoderClient(config);
|
||||
const giteaClient = new GiteaClient(config);
|
||||
|
||||
const concurrency = parseInt(process.env.QUEUE_CONCURRENCY || "2", 10);
|
||||
const queue = new TaskQueue(coderClient, giteaClient, concurrency);
|
||||
|
||||
const app = new Hono();
|
||||
app.use("*", logger());
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Health check
|
||||
// Health check + queue status
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
app.get("/health", (c) => c.json({ status: "ok" }));
|
||||
app.get("/queue", (c) => c.json(queue.status()));
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Webhook endpoints — same paths as the n8n webhooks so Gitea config
|
||||
// can stay unchanged (just point to new host).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
app.post("/webhook/gitea-issue-triage", issueTriage(config, coderClient, giteaClient));
|
||||
app.post("/webhook/gitea-issue-label", issueLabel(config, coderClient, giteaClient));
|
||||
app.post("/webhook/gitea-issue-comment", issueComment(config, coderClient));
|
||||
app.post("/webhook/gitea-pr-review", prReview(config, coderClient, giteaClient));
|
||||
app.post("/webhook/gitea-pr-review-rework", prRework(config, coderClient, giteaClient));
|
||||
app.post("/webhook/gitea-release", release(config, coderClient, giteaClient));
|
||||
app.post("/webhook/gitea-issue-triage", issueTriage(config, queue));
|
||||
app.post("/webhook/gitea-issue-label", issueLabel(config, queue));
|
||||
app.post("/webhook/gitea-issue-comment", issueComment(config, queue));
|
||||
app.post("/webhook/gitea-pr-review", prReview(config, queue, giteaClient));
|
||||
app.post("/webhook/gitea-pr-review-rework", prRework(config, queue));
|
||||
app.post("/webhook/gitea-release", release(config, queue));
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Scheduled maintenance cron (Monday 9:00 AM)
|
||||
@@ -50,7 +55,7 @@ app.post("/webhook/gitea-release", release(config, coderClient, giteaClient));
|
||||
|
||||
const maintenanceRepos = parseMaintenanceRepos();
|
||||
if (maintenanceRepos.length > 0) {
|
||||
const maintenanceFn = runMaintenance(config, coderClient, maintenanceRepos);
|
||||
const maintenanceFn = runMaintenance(config, queue, maintenanceRepos);
|
||||
|
||||
cron.schedule("0 9 * * 1", () => {
|
||||
console.log("[cron] running weekly maintenance");
|
||||
@@ -69,7 +74,7 @@ if (maintenanceRepos.length > 0) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
serve({ fetch: app.fetch, port: config.port }, (info) => {
|
||||
console.log(`SDLC Orchestrator listening on :${info.port}`);
|
||||
console.log(`SDLC Orchestrator listening on :${info.port} (concurrency: ${concurrency})`);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user