From 3beda77b3be0dec9280804388e51d137fdd454e5 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 28 Oct 2024 04:17:17 +0530 Subject: [PATCH] feat: run succes fail handle --- server/src/routes/storage.ts | 22 ++++++++++++++- .../workflow-management/scheduler/index.ts | 27 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/server/src/routes/storage.ts b/server/src/routes/storage.ts index 9428aafe..680ba1a0 100644 --- a/server/src/routes/storage.ts +++ b/server/src/routes/storage.ts @@ -255,11 +255,12 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re }); captureServerAnalytics.capture({ distinctId: req.user?.id, - event: 'maxun-oss-run-created', + event: 'maxun-oss-run-created-manual', properties: { runId: req.params.id, user_id: req.user?.id, created_at: new Date().toISOString(), + status: 'success', } }) try { @@ -279,7 +280,26 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re } } catch (e) { const { message } = e as Error; + // If error occurs, set run status to failed + const run = await Run.findOne({ where: { runId: req.params.id } }); + if (run) { + await run.update({ + status: 'failed', + finishedAt: new Date().toLocaleString(), + }); + } logger.log('info', `Error while running a recording with id: ${req.params.id} - ${message}`); + captureServerAnalytics.capture({ + distinctId: req.user?.id, + event: 'maxun-oss-run-created-manual', + properties: { + runId: req.params.id, + user_id: req.user?.id, + created_at: new Date().toISOString(), + status: 'failed', + error_message: message, + } + }); return res.send(false); } }); diff --git a/server/src/workflow-management/scheduler/index.ts b/server/src/workflow-management/scheduler/index.ts index ae4069a1..98b47d3f 100644 --- a/server/src/workflow-management/scheduler/index.ts +++ b/server/src/workflow-management/scheduler/index.ts @@ -9,6 +9,7 @@ import Robot from "../../models/Robot"; import Run from "../../models/Run"; import { getDecryptedProxyConfig } from "../../routes/proxy"; import { BinaryOutputService } from "../../storage/mino"; +import captureServerAnalytics from "../../utils/analytics"; async function createWorkflowAndStoreMetadata(id: string, userId: string) { try { @@ -132,6 +133,16 @@ async function executeRun(id: string) { binaryOutput: uploadedBinaryOutput, }); + captureServerAnalytics.capture({ + distinctId: id, + event: 'maxun-oss-run-created-scheduled', + properties: { + runId: id, + created_at: new Date().toISOString(), + status: 'success', + } + }); + googleSheetUpdateTasks[id] = { robotId: plainRun.robotMetaId, runId: id, @@ -143,6 +154,22 @@ async function executeRun(id: string) { } catch (error: any) { logger.log('info', `Error while running a recording with id: ${id} - ${error.message}`); console.log(error.message); + const run = await Run.findOne({ where: { runId: id } }); + if (run) { + await run.update({ + status: 'failed', + finishedAt: new Date().toLocaleString(), + }); + } + captureServerAnalytics.capture({ + distinctId: id, + event: 'maxun-oss-run-created-scheduled', + properties: { + runId: id, + created_at: new Date().toISOString(), + status: 'failed', + } + }); return false; } }