feat: use robot & run model in executeWorkflow
This commit is contained in:
@@ -84,21 +84,29 @@ async function runWorkflow(id: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeRun(fileName: string, runId: string) {
|
async function executeRun(id: string) {
|
||||||
try {
|
try {
|
||||||
const recording = await readFile(`./../storage/recordings/${fileName}.json`);
|
const run = await Run.findOne({ where: { runId: id } });
|
||||||
const parsedRecording = JSON.parse(recording);
|
if (!run) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: 'Run not found'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const run = await readFile(`./../storage/runs/${fileName}_${runId}.json`);
|
const plainRun = run.toJSON();
|
||||||
const parsedRun = JSON.parse(run);
|
|
||||||
|
|
||||||
parsedRun.status = 'running';
|
const recording = await Robot.findOne({ where: { 'recording_meta.id': plainRun.robotMetaId }, raw: true });
|
||||||
await saveFile(
|
if (!recording) {
|
||||||
`../storage/runs/${fileName}_${runId}.json`,
|
return {
|
||||||
JSON.stringify(parsedRun, null, 2)
|
success: false,
|
||||||
);
|
error: 'Recording not found'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const browser = browserPool.getRemoteBrowser(parsedRun.browserId);
|
plainRun.status = 'running';
|
||||||
|
|
||||||
|
const browser = browserPool.getRemoteBrowser(plainRun.browserId);
|
||||||
if (!browser) {
|
if (!browser) {
|
||||||
throw new Error('Could not access browser');
|
throw new Error('Could not access browser');
|
||||||
}
|
}
|
||||||
@@ -109,45 +117,31 @@ async function executeRun(fileName: string, runId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const interpretationInfo = await browser.interpreter.InterpretRecording(
|
const interpretationInfo = await browser.interpreter.InterpretRecording(
|
||||||
parsedRecording.recording, currentPage, parsedRun.interpreterSettings);
|
recording.recording, currentPage, plainRun.interpreterSettings);
|
||||||
|
|
||||||
await destroyRemoteBrowser(parsedRun.browserId);
|
await destroyRemoteBrowser(plainRun.browserId);
|
||||||
|
|
||||||
const updated_run_meta = {
|
await run.update({
|
||||||
...parsedRun,
|
...run,
|
||||||
status: 'success',
|
status: 'success',
|
||||||
finishedAt: new Date().toLocaleString(),
|
finishedAt: new Date().toLocaleString(),
|
||||||
browserId: parsedRun.browserId,
|
browserId: plainRun.browserId,
|
||||||
log: interpretationInfo.log.join('\n'),
|
log: interpretationInfo.log.join('\n'),
|
||||||
serializableOutput: interpretationInfo.serializableOutput,
|
serializableOutput: interpretationInfo.serializableOutput,
|
||||||
binaryOutput: interpretationInfo.binaryOutput,
|
binaryOutput: interpretationInfo.binaryOutput,
|
||||||
};
|
});
|
||||||
|
|
||||||
await saveFile(
|
googleSheetUpdateTasks[id] = {
|
||||||
`../storage/runs/${fileName}_${runId}.json`,
|
name: plainRun.name,
|
||||||
JSON.stringify(updated_run_meta, null, 2)
|
runId: id,
|
||||||
);
|
|
||||||
googleSheetUpdateTasks[runId] = {
|
|
||||||
name: parsedRun.name,
|
|
||||||
runId: runId,
|
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
retries: 5,
|
retries: 5,
|
||||||
};
|
};
|
||||||
processGoogleSheetUpdates();
|
processGoogleSheetUpdates();
|
||||||
return true;
|
return true;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.log('info', `Error while running a recording with name: ${fileName}_${runId}.json`);
|
logger.log('info', `Error while running a recording with id: ${id} - ${error.message}`);
|
||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
|
|
||||||
const errorRun = await readFile(`./../storage/runs/${fileName}_${runId}.json`);
|
|
||||||
const parsedErrorRun = JSON.parse(errorRun);
|
|
||||||
parsedErrorRun.status = 'ERROR';
|
|
||||||
parsedErrorRun.log += `\nError: ${error.message}`;
|
|
||||||
await saveFile(
|
|
||||||
`../storage/runs/${fileName}_${runId}.json`,
|
|
||||||
JSON.stringify(parsedErrorRun, null, 2)
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user