(data: ExecuteRunData)
| 128 | }; |
| 129 | |
| 130 | async function processRunExecution(data: ExecuteRunData): Promise<void> { |
| 131 | const BROWSER_INIT_TIMEOUT = 60000; |
| 132 | const BROWSER_PAGE_TIMEOUT = 15000; |
| 133 | |
| 134 | logger.log('info', `Processing run execution job for runId: ${data.runId}, browserId: ${data.browserId}`); |
| 135 | |
| 136 | try { |
| 137 | const run = await Run.findOne({ where: { runId: data.runId } }); |
| 138 | if (!run) { |
| 139 | logger.log('error', `Run ${data.runId} not found in database`); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | if (run.status === 'aborted' || run.status === 'aborting') { |
| 144 | logger.log('info', `Run ${data.runId} has status ${run.status}, skipping execution`); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | if (run.status === 'queued') { |
| 149 | logger.log('info', `Run ${data.runId} has status 'queued', skipping stale execution job`); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | const plainRun = run.toJSON(); |
| 154 | |
| 155 | if ((plainRun.interpreterSettings as any)?.robotType === 'doc-extract') { |
| 156 | logger.log('info', `Run ${data.runId} is a document robot — skipping browser, running document extraction`); |
| 157 | const recording = await Robot.findOne({ where: { 'recording_meta.id': plainRun.robotMetaId }, raw: true }); |
| 158 | if (!recording) { |
| 159 | logger.log('error', `Robot not found for document run ${data.runId}`); |
| 160 | await run.update({ status: 'failed', finishedAt: new Date().toLocaleString(), log: 'Robot not found' }); |
| 161 | return; |
| 162 | } |
| 163 | const { executeDocumentRun } = await import('./utils/document/executeDocumentRun'); |
| 164 | await executeDocumentRun(recording, run, data.userId, serverIo); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | if ((plainRun.interpreterSettings as any)?.robotType === 'doc-parse') { |
| 169 | logger.log('info', `Run ${data.runId} is a document-parse robot — skipping browser, running document parsing`); |
| 170 | const recording = await Robot.findOne({ where: { 'recording_meta.id': plainRun.robotMetaId }, raw: true }); |
| 171 | if (!recording) { |
| 172 | logger.log('error', `Robot not found for document-parse run ${data.runId}`); |
| 173 | await run.update({ status: 'failed', finishedAt: new Date().toLocaleString(), log: 'Robot not found' }); |
| 174 | return; |
| 175 | } |
| 176 | const { executeDocumentParseRun } = await import('./utils/document/executeDocumentParseRun'); |
| 177 | await executeDocumentParseRun(recording, run, data.userId, serverIo); |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | const browserId = data.browserId || plainRun.browserId; |
| 182 | |
| 183 | if (!browserId) throw new Error(`No browser ID available for run ${data.runId}`); |
| 184 | |
| 185 | logger.log('info', `Looking for browser ${browserId} for run ${data.runId}`); |
| 186 | |
| 187 | let browser = browserPool.getRemoteBrowser(browserId); |
no test coverage detected