feat: run succes fail handle
This commit is contained in:
@@ -255,11 +255,12 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re
|
|||||||
});
|
});
|
||||||
captureServerAnalytics.capture({
|
captureServerAnalytics.capture({
|
||||||
distinctId: req.user?.id,
|
distinctId: req.user?.id,
|
||||||
event: 'maxun-oss-run-created',
|
event: 'maxun-oss-run-created-manual',
|
||||||
properties: {
|
properties: {
|
||||||
runId: req.params.id,
|
runId: req.params.id,
|
||||||
user_id: req.user?.id,
|
user_id: req.user?.id,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
|
status: 'success',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
@@ -279,7 +280,26 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const { message } = e as Error;
|
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}`);
|
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);
|
return res.send(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Robot from "../../models/Robot";
|
|||||||
import Run from "../../models/Run";
|
import Run from "../../models/Run";
|
||||||
import { getDecryptedProxyConfig } from "../../routes/proxy";
|
import { getDecryptedProxyConfig } from "../../routes/proxy";
|
||||||
import { BinaryOutputService } from "../../storage/mino";
|
import { BinaryOutputService } from "../../storage/mino";
|
||||||
|
import captureServerAnalytics from "../../utils/analytics";
|
||||||
|
|
||||||
async function createWorkflowAndStoreMetadata(id: string, userId: string) {
|
async function createWorkflowAndStoreMetadata(id: string, userId: string) {
|
||||||
try {
|
try {
|
||||||
@@ -132,6 +133,16 @@ async function executeRun(id: string) {
|
|||||||
binaryOutput: uploadedBinaryOutput,
|
binaryOutput: uploadedBinaryOutput,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
captureServerAnalytics.capture({
|
||||||
|
distinctId: id,
|
||||||
|
event: 'maxun-oss-run-created-scheduled',
|
||||||
|
properties: {
|
||||||
|
runId: id,
|
||||||
|
created_at: new Date().toISOString(),
|
||||||
|
status: 'success',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
googleSheetUpdateTasks[id] = {
|
googleSheetUpdateTasks[id] = {
|
||||||
robotId: plainRun.robotMetaId,
|
robotId: plainRun.robotMetaId,
|
||||||
runId: id,
|
runId: id,
|
||||||
@@ -143,6 +154,22 @@ async function executeRun(id: string) {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.log('info', `Error while running a recording with id: ${id} - ${error.message}`);
|
logger.log('info', `Error while running a recording with id: ${id} - ${error.message}`);
|
||||||
console.log(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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user