mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-17 07:20:51 +08:00
Synchronize scheduler concurrency across API and gRPC processes and restore persisted limits during recovery. Serialize subscription mutations and preserve shared storage while cleaning Shell and CLI namespaces, historical references, and filesystem-specific naming candidates. Handle CLI text responses correctly and include script history in backups. Add regression coverage for concurrency, cleanup ownership, long URLs, Unicode paths, and history exports.
27 lines
795 B
TypeScript
27 lines
795 B
TypeScript
import { ServerUnaryCall, sendUnaryData, status } from '@grpc/grpc-js';
|
|
import os from 'os';
|
|
import { AddCronResponse, SetConcurrencyRequest } from '../protos/cron';
|
|
import taskLimit from '../shared/pLimit';
|
|
|
|
export async function setConcurrency(
|
|
call: ServerUnaryCall<SetConcurrencyRequest, AddCronResponse>,
|
|
callback: sendUnaryData<AddCronResponse>,
|
|
) {
|
|
const limit = call.request.concurrency;
|
|
if (!Number.isInteger(limit) || limit < 0 || limit > 2147483647) {
|
|
callback(
|
|
Object.assign(new Error('Invalid concurrency'), {
|
|
code: status.INVALID_ARGUMENT,
|
|
}),
|
|
null,
|
|
);
|
|
return;
|
|
}
|
|
try {
|
|
await taskLimit.setCustomLimit(limit || Math.max(os.cpus().length, 4));
|
|
callback(null, {});
|
|
} catch (error) {
|
|
callback(error as Error, null);
|
|
}
|
|
}
|