Persist jobs, push repos, systemd for generated MCPs

This commit is contained in:
root
2026-03-12 10:21:51 +00:00
parent 6eabd3d3de
commit 91a2f1b602
4 changed files with 110 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
import { randomUUID } from 'crypto';
import fs from 'fs';
import path from 'path';
import type { MetaRequest, MetaResponse } from './types.js';
export type Job = {
@@ -9,8 +11,26 @@ export type Job = {
response: MetaResponse;
};
const storagePath = '/root/.meta-mcp/jobs.json';
const jobs = new Map<string, Job>();
function persist() {
const dir = path.dirname(storagePath);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(storagePath, JSON.stringify([...jobs.values()], null, 2));
}
function hydrate() {
if (!fs.existsSync(storagePath)) return;
const raw = fs.readFileSync(storagePath, 'utf8');
const parsed = JSON.parse(raw) as Job[];
for (const job of parsed) {
jobs.set(job.id, job);
}
}
hydrate();
export function createJob(request: MetaRequest): Job {
const id = randomUUID();
const now = Date.now();
@@ -21,6 +41,7 @@ export function createJob(request: MetaRequest): Job {
};
const job: Job = { id, request, createdAt: now, updatedAt: now, response };
jobs.set(id, job);
persist();
return job;
}
@@ -28,7 +49,12 @@ export function updateJob(id: string, patch: Partial<MetaResponse>): Job | null
const job = jobs.get(id);
if (!job) return null;
job.updatedAt = Date.now();
if (patch.logs?.length) {
const existing = job.response.logs ?? [];
patch.logs = [...existing, ...patch.logs].slice(-200);
}
job.response = { ...job.response, ...patch };
persist();
return job;
}