From 4a095ea5480976418e851719ed0db11826233ab6 Mon Sep 17 00:00:00 2001 From: Rohit Rajan Date: Sat, 12 Sep 2026 00:33:59 +0530 Subject: [PATCH] fix: address coderabbit review --- server/src/api/record.ts | 20 +++++++++++++++- .../workflow-management/scheduler/index.ts | 23 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 7afdb2fe..ffc1dfe7 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -628,12 +628,30 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string, runSou jobKey: `${QUEUE_NAMES.EXECUTE_RUN}:${plainRun.runId}`, }); } catch (queueError: any) { + const finishedAt = new Date().toLocaleString(); await run.update({ status: 'failed', - finishedAt: new Date().toLocaleString(), + finishedAt, log: `Failed to queue execution job: ${queueError.message}`, }); + try { + serverIo.of('/queued-run').to(`user-${userId}`).emit('run-completed', { + runId: plainRun.runId, + robotMetaId: plainRun.robotMetaId, + robotName: plainRun.name, + status: 'failed', + finishedAt, + runByUserId: plainRun.runByUserId, + runByScheduleId: plainRun.runByScheduleId, + runByAPI: plainRun.runByAPI || false, + browserId: plainRun.browserId, + error: `Failed to queue execution job: ${queueError.message}`, + }); + } catch (socketError: any) { + logger.log('warn', `Failed to emit queue failure for API run ${plainRun.runId}: ${socketError.message}`); + } + if (!isDocRobot) { try { await destroyRemoteBrowser(browserId, userId); diff --git a/server/src/workflow-management/scheduler/index.ts b/server/src/workflow-management/scheduler/index.ts index 31dbcc15..69c1b5fc 100644 --- a/server/src/workflow-management/scheduler/index.ts +++ b/server/src/workflow-management/scheduler/index.ts @@ -123,12 +123,33 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string) { jobKey: `${QUEUE_NAMES.EXECUTE_RUN}:${plainRun.runId}`, }); } catch (queueError: any) { + const finishedAt = new Date().toLocaleString(); await run.update({ status: 'failed', - finishedAt: new Date().toLocaleString(), + finishedAt, log: `Failed to queue scheduled execution job: ${queueError.message}`, }); + const failureSocketData = { + runId: plainRun.runId, + robotMetaId: plainRun.robotMetaId, + robotName: plainRun.name, + status: 'failed', + finishedAt, + runByUserId: plainRun.runByUserId, + runByScheduleId: plainRun.runByScheduleId, + runByAPI: plainRun.runByAPI || false, + browserId: plainRun.browserId, + error: `Failed to queue scheduled execution job: ${queueError.message}`, + }; + + try { + serverIo.of(browserId).emit('run-completed', failureSocketData); + serverIo.of('/queued-run').to(`user-${userId}`).emit('run-completed', failureSocketData); + } catch (socketError: any) { + logger.log('warn', `Failed to emit queue failure for scheduled run ${plainRun.runId}: ${socketError.message}`); + } + if (!isDocRobot) { try { await destroyRemoteBrowser(browserId, userId);