feat: successful run + interpretation of robots

This commit is contained in:
karishmas6
2024-10-10 02:23:33 +05:30
parent a30c08b819
commit 590e7e9d9f

View File

@@ -207,37 +207,39 @@ router.post('/runs/run/:id', requireSignIn, async (req, res) => {
// const parsedRun = JSON.parse(run); // const parsedRun = JSON.parse(run);
console.log(`Params for POST /runs/run/:id`, req.params.id) console.log(`Params for POST /runs/run/:id`, req.params.id)
const run = await Run.findOne({ where: { runId: req.params.id }, raw: true }); const run = await Run.findOne({ where: { runId: req.params.id } });
if (!run) { if (!run) {
return res.status(404).send(false); return res.status(404).send(false);
} }
console.log(`found run: ${run}`) console.log(`found run: ${run}`)
const recording = await Robot.findOne({ where: { 'recording_meta.id': run.robotMetaId }, raw: true }); const plainRun = run.toJSON();
const recording = await Robot.findOne({ where: { 'recording_meta.id': plainRun.robotMetaId }, raw: true });
if (!recording) { if (!recording) {
return res.status(404).send(false); return res.status(404).send(false);
} }
// interpret the run in active browser // interpret the run in active browser
const browser = browserPool.getRemoteBrowser(run.browserId); const browser = browserPool.getRemoteBrowser(plainRun.browserId);
const currentPage = browser?.getCurrentPage(); const currentPage = browser?.getCurrentPage();
if (browser && currentPage) { if (browser && currentPage) {
const interpretationInfo = await browser.interpreter.InterpretRecording( const interpretationInfo = await browser.interpreter.InterpretRecording(
recording.recording, currentPage, run.interpreterSettings); recording.recording, currentPage, plainRun.interpreterSettings);
await destroyRemoteBrowser(run.browserId); await destroyRemoteBrowser(plainRun.browserId);
await run.update({ await run.update({
...run, ...run,
status: 'success', status: 'success',
finishedAt: new Date().toLocaleString(), finishedAt: new Date().toLocaleString(),
browserId: run.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,
}); });
googleSheetUpdateTasks[req.params.id] = { googleSheetUpdateTasks[req.params.id] = {
name: run.name, name: plainRun.name,
runId: run.runId, runId: plainRun.runId,
status: 'pending', status: 'pending',
retries: 5, retries: 5,
}; };
@@ -351,7 +353,7 @@ router.put('/schedule/:fileName/', requireSignIn, async (req, res) => {
router.post('/runs/abort/:id', requireSignIn, async (req, res) => { router.post('/runs/abort/:id', requireSignIn, async (req, res) => {
try { try {
console.log(`Params for POST /runs/abort/:id`, req.params.id) console.log(`Params for POST /runs/abort/:id`, req.params.id)
const run = await Run.findOne({ where: { runId: req.params.id }, raw: true }); const run = await Run.findOne({ where: { runId: req.params.id }});
if (!run) { if (!run) {
return res.status(404).send(false); return res.status(404).send(false);
} }