Initial push of Plunk Next

This commit is contained in:
Dries Augustyns
2025-12-01 09:56:56 +01:00
parent 07cea20262
commit ff1876d580
566 changed files with 89036 additions and 28423 deletions
@@ -0,0 +1,48 @@
/**
* Background Job: Workflow Queue Processor
* Processes workflow steps from the queue (for delayed steps)
*/
import {type Job, Worker} from 'bullmq';
import {workflowQueue, type WorkflowStepJobData} from '../services/QueueService.js';
import {WorkflowExecutionService} from '../services/WorkflowExecutionService.js';
export function createWorkflowWorker() {
const worker = new Worker<WorkflowStepJobData>(
workflowQueue.name,
async (job: Job<WorkflowStepJobData>) => {
const {executionId, stepId, type, stepExecutionId} = job.data;
if (type === 'timeout') {
// Handle timeout for WAIT_FOR_EVENT steps
if (!stepExecutionId) {
throw new Error('stepExecutionId is required for timeout jobs');
}
await WorkflowExecutionService.processTimeout(executionId, stepId, stepExecutionId);
} else {
// Handle regular step execution
await WorkflowExecutionService.processStepExecution(executionId, stepId);
}
},
{
connection: workflowQueue.opts.connection,
concurrency: 10, // Process up to 10 workflow steps concurrently
},
);
worker.on('completed', job => {
console.log(`[WORKFLOW-PROCESSOR] Job ${job.id} completed`);
});
worker.on('failed', (job, err) => {
console.error(`[WORKFLOW-PROCESSOR] Job ${job?.id} failed:`, err.message);
});
worker.on('error', err => {
console.error('[WORKFLOW-PROCESSOR] Worker error:', err);
});
return worker;
}