refactor: use capture
This commit is contained in:
@@ -15,7 +15,7 @@ import { BinaryOutputService } from '../storage/mino';
|
|||||||
import { workflowQueue } from '../worker';
|
import { workflowQueue } from '../worker';
|
||||||
import { AuthenticatedRequest } from './record';
|
import { AuthenticatedRequest } from './record';
|
||||||
import { computeNextRun } from '../utils/schedule';
|
import { computeNextRun } from '../utils/schedule';
|
||||||
import captureServerAnalytics from "../utils/analytics";
|
import { capture } from "../utils/analytics";
|
||||||
|
|
||||||
export const router = Router();
|
export const router = Router();
|
||||||
|
|
||||||
@@ -68,15 +68,14 @@ router.delete('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest
|
|||||||
await Robot.destroy({
|
await Robot.destroy({
|
||||||
where: { 'recording_meta.id': req.params.id }
|
where: { 'recording_meta.id': req.params.id }
|
||||||
});
|
});
|
||||||
captureServerAnalytics.capture({
|
capture(
|
||||||
distinctId: req.user?.id,
|
'maxun-oss-robot-deleted',
|
||||||
event: 'maxun-oss-robot-deleted',
|
{
|
||||||
properties: {
|
|
||||||
robotId: req.params.id,
|
robotId: req.params.id,
|
||||||
user_id: req.user?.id,
|
user_id: req.user?.id,
|
||||||
deleted_at: new Date().toISOString(),
|
deleted_at: new Date().toISOString(),
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
return res.send(true);
|
return res.send(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const { message } = e as Error;
|
const { message } = e as Error;
|
||||||
@@ -107,15 +106,14 @@ router.delete('/runs/:id', requireSignIn, async (req: AuthenticatedRequest, res)
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await Run.destroy({ where: { runId: req.params.id } });
|
await Run.destroy({ where: { runId: req.params.id } });
|
||||||
captureServerAnalytics.capture({
|
capture(
|
||||||
distinctId: req.user?.id,
|
'maxun-oss-run-deleted',
|
||||||
event: 'maxun-oss-run-deleted',
|
{
|
||||||
properties: {
|
|
||||||
runId: req.params.id,
|
runId: req.params.id,
|
||||||
user_id: req.user?.id,
|
user_id: req.user?.id,
|
||||||
deleted_at: new Date().toISOString(),
|
deleted_at: new Date().toISOString(),
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
return res.send(true);
|
return res.send(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const { message } = e as Error;
|
const { message } = e as Error;
|
||||||
@@ -259,7 +257,7 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re
|
|||||||
let extractedItemsCount = 0;
|
let extractedItemsCount = 0;
|
||||||
|
|
||||||
if (run.dataValues.binaryOutput) {
|
if (run.dataValues.binaryOutput) {
|
||||||
extractedScreenshotsCount = run.dataValues.binaryOutput['item-0'].length;
|
extractedScreenshotsCount = run.dataValues.binaryOutput['item-0'].length;
|
||||||
}
|
}
|
||||||
if (run.dataValues.serializableOutput) {
|
if (run.dataValues.serializableOutput) {
|
||||||
extractedItemsCount = run.dataValues.serializableOutput['item-0'].length;
|
extractedItemsCount = run.dataValues.serializableOutput['item-0'].length;
|
||||||
@@ -267,10 +265,9 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re
|
|||||||
|
|
||||||
console.log(`${extractedItemsCount} ${extractedScreenshotsCount}`)
|
console.log(`${extractedItemsCount} ${extractedScreenshotsCount}`)
|
||||||
|
|
||||||
captureServerAnalytics.capture({
|
capture(
|
||||||
distinctId: req.user?.id,
|
'maxun-oss-run-created-manual',
|
||||||
event: 'maxun-oss-run-created-manual',
|
{
|
||||||
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(),
|
||||||
@@ -278,7 +275,7 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re
|
|||||||
extractedItemsCount,
|
extractedItemsCount,
|
||||||
extractedScreenshotsCount,
|
extractedScreenshotsCount,
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
try {
|
try {
|
||||||
googleSheetUpdateTasks[plainRun.runId] = {
|
googleSheetUpdateTasks[plainRun.runId] = {
|
||||||
robotId: plainRun.robotMetaId,
|
robotId: plainRun.robotMetaId,
|
||||||
@@ -305,17 +302,16 @@ router.post('/runs/run/:id', requireSignIn, async (req: AuthenticatedRequest, re
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
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({
|
capture(
|
||||||
distinctId: req.user?.id,
|
'maxun-oss-run-created-manual',
|
||||||
event: 'maxun-oss-run-created-manual',
|
{
|
||||||
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: 'failed',
|
status: 'failed',
|
||||||
error_message: message,
|
error_message: message,
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
return res.send(false);
|
return res.send(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -421,15 +417,14 @@ router.put('/schedule/:id/', requireSignIn, async (req: AuthenticatedRequest, re
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
captureServerAnalytics.capture({
|
capture(
|
||||||
distinctId: req.user.id,
|
'maxun-oss-robot-scheduled',
|
||||||
event: 'maxun-oss-robot-scheduled',
|
{
|
||||||
properties: {
|
|
||||||
robotId: id,
|
robotId: id,
|
||||||
user_id: req.user.id,
|
user_id: req.user.id,
|
||||||
scheduled_at: new Date().toISOString(),
|
scheduled_at: new Date().toISOString(),
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
// Fetch updated schedule details after setting it
|
// Fetch updated schedule details after setting it
|
||||||
const updatedRobot = await Robot.findOne({ where: { 'recording_meta.id': id } });
|
const updatedRobot = await Robot.findOne({ where: { 'recording_meta.id': id } });
|
||||||
@@ -491,15 +486,14 @@ router.delete('/schedule/:id', requireSignIn, async (req: AuthenticatedRequest,
|
|||||||
schedule: null
|
schedule: null
|
||||||
});
|
});
|
||||||
|
|
||||||
captureServerAnalytics.capture({
|
capture(
|
||||||
distinctId: req.user?.id,
|
'maxun-oss-robot-schedule-deleted',
|
||||||
event: 'maxun-oss-robot-schedule-deleted',
|
{
|
||||||
properties: {
|
|
||||||
robotId: id,
|
robotId: id,
|
||||||
user_id: req.user?.id,
|
user_id: req.user?.id,
|
||||||
unscheduled_at: new Date().toISOString(),
|
unscheduled_at: new Date().toISOString(),
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
res.status(200).json({ message: 'Schedule deleted successfully' });
|
res.status(200).json({ message: 'Schedule deleted successfully' });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user