- GroupQueue recovery mode: limit to 3 concurrent agents for 60s after restart to prevent API rate-limit storms (configurable via env vars) - getErrorMessage: replace 14 occurrences of instanceof Error pattern - readJsonFile/writeJsonFile: replace 19 occurrences of JSON+fs pattern - fetchWithTimeout: replace 3 occurrences of AbortController pattern 354/354 tests passing
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
import {
|
|
resolveGroupIpcPath,
|
|
resolveTaskRuntimeIpcPath,
|
|
} from './group-folder.js';
|
|
import { writeJsonFile } from './utils.js';
|
|
|
|
export function writeTasksSnapshot(
|
|
groupFolder: string,
|
|
isMain: boolean,
|
|
tasks: Array<{
|
|
id: string;
|
|
groupFolder: string;
|
|
prompt: string;
|
|
schedule_type: string;
|
|
schedule_value: string;
|
|
status: string;
|
|
next_run: string | null;
|
|
}>,
|
|
runtimeTaskId?: string,
|
|
): void {
|
|
const groupIpcDir = runtimeTaskId
|
|
? resolveTaskRuntimeIpcPath(groupFolder, runtimeTaskId)
|
|
: resolveGroupIpcPath(groupFolder);
|
|
fs.mkdirSync(groupIpcDir, { recursive: true });
|
|
const filteredTasks = isMain
|
|
? tasks
|
|
: tasks.filter((t) => t.groupFolder === groupFolder);
|
|
const tasksFile = path.join(groupIpcDir, 'current_tasks.json');
|
|
writeJsonFile(tasksFile, filteredTasks, true);
|
|
}
|
|
|
|
export interface AvailableGroup {
|
|
jid: string;
|
|
name: string;
|
|
lastActivity: string;
|
|
isRegistered: boolean;
|
|
}
|
|
|
|
export function writeGroupsSnapshot(
|
|
groupFolder: string,
|
|
isMain: boolean,
|
|
groups: AvailableGroup[],
|
|
_registeredJids?: Set<string>,
|
|
): void {
|
|
const groupIpcDir = resolveGroupIpcPath(groupFolder);
|
|
fs.mkdirSync(groupIpcDir, { recursive: true });
|
|
const visibleGroups = isMain ? groups : [];
|
|
const groupsFile = path.join(groupIpcDir, 'available_groups.json');
|
|
writeJsonFile(
|
|
groupsFile,
|
|
{ groups: visibleGroups, lastSync: new Date().toISOString() },
|
|
true,
|
|
);
|
|
}
|