From 0b8b735289b19e3b91dddbf354d34d98f89a7a2f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 12 Sep 2024 21:05:49 +0530 Subject: [PATCH] chore: -rm comments --- .../src/workflow-management/scheduler/index.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/server/src/workflow-management/scheduler/index.ts b/server/src/workflow-management/scheduler/index.ts index c5388948..f8043a70 100644 --- a/server/src/workflow-management/scheduler/index.ts +++ b/server/src/workflow-management/scheduler/index.ts @@ -38,21 +38,17 @@ export const worker = new Worker('workflow', async job => { } }, { connection }); -// Listen for job completion and close worker/queue worker.on('completed', async (job: any) => { console.log(`Job ${job.id} completed for ${job.data.fileName}_${job.data.runId}`); - // Gracefully close the worker and queue await worker.close(); await workflowQueue.close(); console.log('Worker and queue have been closed.'); }); -// Listen for job failure and close worker/queue worker.on('failed', async (job: any, err) => { console.error(`Job ${job.id} failed for ${job.data.fileName}_${job.data.runId}:`, err); - // Gracefully close the worker and queue await worker.close(); await workflowQueue.close(); console.log('Worker and queue have been closed after failure.'); @@ -110,23 +106,18 @@ async function runWorkflow(fileName: string, runId: string) { async function executeRun(fileName: string, runId: string) { try { - // Read the recording from storage const recording = await readFile(`./../storage/recordings/${fileName}.waw.json`); const parsedRecording = JSON.parse(recording); - // Read the run from storage const run = await readFile(`./../storage/runs/${fileName}_${runId}.json`); const parsedRun = JSON.parse(run); - // Update status to RUNNING parsedRun.status = 'RUNNING'; await saveFile( `../storage/runs/${fileName}_${runId}.json`, JSON.stringify(parsedRun, null, 2) ); - // Interpret the run in active browser - const browser = browserPool.getRemoteBrowser(parsedRun.browserId); if (!browser) { throw new Error('Could not access browser'); @@ -166,7 +157,6 @@ async function executeRun(fileName: string, runId: string) { logger.log('info', `Error while running a recording with name: ${fileName}_${runId}.json`); console.log(error.message); - // Update run status to ERROR const errorRun = await readFile(`./../storage/runs/${fileName}_${runId}.json`); const parsedErrorRun = JSON.parse(errorRun); parsedErrorRun.status = 'ERROR'; @@ -188,7 +178,7 @@ async function readyForRunHandler(browserId: string, fileName: string, runId: st logger.log('info', `Interpretation of ${fileName} succeeded`); } else { logger.log('error', `Interpretation of ${fileName} failed`); - await destroyRemoteBrowser(browserId); // Destroy browser if failed + await destroyRemoteBrowser(browserId); } resetRecordingState(browserId, fileName, runId); @@ -200,7 +190,6 @@ async function readyForRunHandler(browserId: string, fileName: string, runId: st } function resetRecordingState(browserId: string, fileName: string, runId: string) { - // Reset the running recording name, log, and run id to empty strings browserId = ''; fileName = ''; runId = ''; @@ -212,12 +201,10 @@ async function handleRunRecording(fileName: string, runId: string) { const result = await runWorkflow(fileName, runId); const { browserId, runId: newRunId } = result; - // Type guard to ensure browserId and newRunId are defined if (!browserId || !newRunId) { throw new Error('browserId or runId is undefined'); } - // Initialize socket connection const socket = io(`http://localhost:8080/${browserId}`, { transports: ['websocket'], rejectUnauthorized: false @@ -225,10 +212,8 @@ async function handleRunRecording(fileName: string, runId: string) { socket.on('ready-for-run', () => readyForRunHandler(browserId, fileName, newRunId)); - // Log or notify that the recording is running logger.log('info', `Running recording: ${fileName}`); - // Cleanup should only happen after the run is completed socket.on('disconnect', () => { cleanupSocketListeners(socket, browserId, newRunId); });