refactor: use capture

This commit is contained in:
karishmas6
2024-10-29 03:46:13 +05:30
parent 9a851a8650
commit 12eee989a1
3 changed files with 27 additions and 20 deletions

View File

@@ -21,7 +21,7 @@ import fs from "fs";
import { getBestSelectorForAction } from "../utils"; import { getBestSelectorForAction } from "../utils";
import { browserPool } from "../../server"; import { browserPool } from "../../server";
import { uuid } from "uuidv4"; import { uuid } from "uuidv4";
import captureServerAnalytics from "../../utils/analytics" import { capture } from "../../utils/analytics"
interface PersistedGeneratedData { interface PersistedGeneratedData {
lastUsedSelector: string; lastUsedSelector: string;
@@ -496,14 +496,13 @@ export class WorkflowGenerator {
recording_meta: this.recordingMeta, recording_meta: this.recordingMeta,
recording: recording, recording: recording,
}); });
captureServerAnalytics.capture({ capture(
distinctId: userId.toString(), 'maxun-oss-robot-created',
event: 'maxun-oss-robot-created', {
properties: {
robot_meta: robot.recording_meta, robot_meta: robot.recording_meta,
recording: robot.recording, recording: robot.recording,
} }
}) )
logger.log('info', `Robot saved with id: ${robot.id}`); logger.log('info', `Robot saved with id: ${robot.id}`);
} }

View File

@@ -24,8 +24,18 @@ export async function updateGoogleSheet(robotId: string, runId: string) {
const plainRun = run.toJSON(); const plainRun = run.toJSON();
if (plainRun.status === 'success' && plainRun.serializableOutput) { if (plainRun.status === 'success') {
const data = plainRun.serializableOutput['item-0'] as { [key: string]: any }[]; let data: { [key: string]: any }[] = [];
if (plainRun.serializableOutput && Object.keys(plainRun.serializableOutput).length > 0) {
data = plainRun.serializableOutput['item-0'] as { [key: string]: any }[];
} else if (plainRun.binaryOutput && plainRun.binaryOutput['item-0']) {
// Handle binaryOutput by setting the URL as a data entry
const binaryUrl = plainRun.binaryOutput['item-0'] as string;
// Create a placeholder object with the binary URL
data = [{ "Screenshot URL": binaryUrl }];
}
const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } }); const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId } });

View File

@@ -9,7 +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"; import { capture } from "../../utils/analytics";
async function createWorkflowAndStoreMetadata(id: string, userId: string) { async function createWorkflowAndStoreMetadata(id: string, userId: string) {
try { try {
@@ -50,7 +50,7 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string) {
const runId = uuid(); const runId = uuid();
const run = await Run.create({ const run = await Run.create({
status: 'Scheduled', status: 'scheduled',
name: recording.recording_meta.name, name: recording.recording_meta.name,
robotId: recording.id, robotId: recording.id,
robotMetaId: recording.recording_meta.id, robotMetaId: recording.recording_meta.id,
@@ -139,10 +139,9 @@ async function executeRun(id: string) {
} }
); );
captureServerAnalytics.capture({ capture(
distinctId: id, 'maxun-oss-run-created-scheduled',
event: 'maxun-oss-run-created-scheduled', {
properties: {
runId: id, runId: id,
created_at: new Date().toISOString(), created_at: new Date().toISOString(),
status: 'success', status: 'success',
@@ -150,7 +149,7 @@ async function executeRun(id: string) {
extractedRowsCount: totalRowsExtracted, extractedRowsCount: totalRowsExtracted,
extractedScreenshotsCount: run.dataValues.binaryOutput['item-0'].length, extractedScreenshotsCount: run.dataValues.binaryOutput['item-0'].length,
} }
}); );
googleSheetUpdateTasks[id] = { googleSheetUpdateTasks[id] = {
robotId: plainRun.robotMetaId, robotId: plainRun.robotMetaId,
@@ -170,15 +169,14 @@ async function executeRun(id: string) {
finishedAt: new Date().toLocaleString(), finishedAt: new Date().toLocaleString(),
}); });
} }
captureServerAnalytics.capture({ capture(
distinctId: id, 'maxun-oss-run-created-scheduled',
event: 'maxun-oss-run-created-scheduled', {
properties: {
runId: id, runId: id,
created_at: new Date().toISOString(), created_at: new Date().toISOString(),
status: 'failed', status: 'failed',
} }
}); );
return false; return false;
} }
} }