44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.createJob = createJob;
|
|
exports.getJob = getJob;
|
|
exports.updateJob = updateJob;
|
|
exports.listJobs = listJobs;
|
|
const uuid_1 = require("uuid");
|
|
// ---------------------------------------------------------------------------
|
|
// In-memory store (swap for Redis/DB if scaling horizontally)
|
|
// ---------------------------------------------------------------------------
|
|
const store = new Map();
|
|
function createJob(agent, task, repo) {
|
|
const job = {
|
|
id: (0, uuid_1.v4)(),
|
|
agent,
|
|
task,
|
|
repo,
|
|
status: 'queued',
|
|
progress: 'Job queued',
|
|
toolCalls: [],
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString()
|
|
};
|
|
store.set(job.id, job);
|
|
return job;
|
|
}
|
|
function getJob(id) {
|
|
return store.get(id);
|
|
}
|
|
function updateJob(id, updates) {
|
|
const job = store.get(id);
|
|
if (!job)
|
|
return undefined;
|
|
const updated = { ...job, ...updates, id, updatedAt: new Date().toISOString() };
|
|
store.set(id, updated);
|
|
return updated;
|
|
}
|
|
function listJobs(limit = 50) {
|
|
const all = Array.from(store.values());
|
|
return all
|
|
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
|
.slice(0, limit);
|
|
}
|