Files
devclaw-gitea/lib/services/queue.ts
Lauren ten Hoor f2e71a35d8 feat: implement work heartbeat service for health checks and task dispatching
- Introduced a new heartbeat service that runs at defined intervals to perform health checks on workers and fill available task slots based on priority.
- Added a health tool to scan worker health across projects with optional auto-fix capabilities.
- Updated the status tool to provide a lightweight overview of worker states and queue counts without health checks.
- Enhanced task creation tool descriptions to clarify task state handling.
- Implemented tests for the work heartbeat logic, ensuring proper project resolution, worker state management, and task prioritization.
2026-02-11 01:04:30 +08:00

50 lines
1.7 KiB
TypeScript

/**
* Queue service — issue queue fetching.
*
* Fetches issue queues per project from the issue provider.
* Pure functions, no tool registration or state mutation.
*/
import type { Issue } from "../providers/provider.js";
import { createProvider } from "../providers/index.js";
import type { Project } from "../projects.js";
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
export type QueueLabel = "To Improve" | "To Test" | "To Do";
export const QUEUE_PRIORITY: Record<QueueLabel, number> = {
"To Improve": 3,
"To Test": 2,
"To Do": 1,
};
export function getTaskPriority(label: QueueLabel, issue: Issue): number {
return QUEUE_PRIORITY[label] * 10000 - issue.iid;
}
export function getRoleForLabel(label: QueueLabel): "dev" | "qa" {
return label === "To Test" ? "qa" : "dev";
}
// ---------------------------------------------------------------------------
// Fetching
// ---------------------------------------------------------------------------
export async function fetchProjectQueues(project: Project): Promise<Record<QueueLabel, Issue[]>> {
const { provider } = createProvider({ repo: project.repo });
const labels: QueueLabel[] = ["To Improve", "To Test", "To Do"];
const queues: Record<QueueLabel, Issue[]> = { "To Improve": [], "To Test": [], "To Do": [] };
for (const label of labels) {
try {
const issues = await provider.listIssuesByLabel(label);
queues[label] = issues.sort((a, b) => getTaskPriority(label, b) - getTaskPriority(label, a));
} catch {
queues[label] = [];
}
}
return queues;
}