Add a limit to workflow queue per workspace (#12908)
- new status `ENQUEUED` added. With a command to backfill - counter in cache per workspace, managed by a new service [workflow-run-queue.workspace-service.ts](https://github.com/twentyhq/twenty/compare/tt-improve-workflow-run-queueing?expand=1#diff-1e2de2a48cd482a3bd7e8dedf1150a19d0b200afbd9282181a24ecddddb56927) - cron added that will run every minute to look for not started workflows Here is the new flow: - When executing a workflow, we check if the queue is not full. If not, run is created as `ENQUEUED` and the run workflow job is triggered as usual. If full, create the run as NOT_STARTED and do not trigger the job - Cron will look for NOT_STARTED workflows and queue some if there is some place again - Only MANUAL and Form submit skip the queue limit
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
export enum CacheStorageNamespace {
|
||||
ModuleMessaging = 'module:messaging',
|
||||
ModuleCalendar = 'module:calendar',
|
||||
ModuleWorkflow = 'module:workflow',
|
||||
EngineWorkspace = 'engine:workspace',
|
||||
EngineHealth = 'engine:health',
|
||||
}
|
||||
|
||||
@ -20,4 +20,5 @@ export enum MetricsKeys {
|
||||
WorkflowRunCompleted = 'workflow-run/completed',
|
||||
WorkflowRunFailed = 'workflow-run/failed',
|
||||
WorkflowRunFailedThrottled = 'workflow-run/failed/throttled',
|
||||
WorkflowRunFailedToEnqueue = 'workflow-run/failed/to-enqueue',
|
||||
}
|
||||
|
||||
@ -7,5 +7,5 @@ export class ThrottlerException extends CustomException {
|
||||
}
|
||||
|
||||
export enum ThrottlerExceptionCode {
|
||||
TOO_MANY_REQUESTS = 'TOO_MANY_REQUESTS',
|
||||
LIMIT_REACHED = 'LIMIT_REACHED',
|
||||
}
|
||||
|
||||
@ -20,8 +20,8 @@ export class ThrottlerService {
|
||||
|
||||
if (currentCount >= limit) {
|
||||
throw new ThrottlerException(
|
||||
'Too many requests',
|
||||
ThrottlerExceptionCode.TOO_MANY_REQUESTS,
|
||||
'Limit reached',
|
||||
ThrottlerExceptionCode.LIMIT_REACHED,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user