Merge branch 'develop' into perf-v11
This commit is contained in:
@@ -151,8 +151,8 @@ export class WorkflowGenerator {
|
||||
workflow: [],
|
||||
});
|
||||
socket.on('activeIndex', (data) => this.generatedData.lastIndex = parseInt(data));
|
||||
socket.on('decision', async ({ pair, actionType, decision }) => {
|
||||
const id = browserPool.getActiveBrowserId();
|
||||
socket.on('decision', async ({ pair, actionType, decision, userId }) => {
|
||||
const id = browserPool.getActiveBrowserId(userId);
|
||||
if (id) {
|
||||
// const activeBrowser = browserPool.getRemoteBrowser(id);
|
||||
// const currentPage = activeBrowser?.getCurrentPage();
|
||||
@@ -826,6 +826,7 @@ export class WorkflowGenerator {
|
||||
selectors?.testIdSelector,
|
||||
selectors?.id,
|
||||
selectors?.hrefSelector,
|
||||
selectors?.relSelector,
|
||||
selectors?.accessibilitySelector,
|
||||
selectors?.attrSelector
|
||||
]
|
||||
|
||||
@@ -49,11 +49,7 @@ export async function updateGoogleSheet(robotId: string, runId: string) {
|
||||
if (plainRobot.google_sheet_email && spreadsheetId) {
|
||||
console.log(`Preparing to write data to Google Sheet for robot: ${robotId}, spreadsheetId: ${spreadsheetId}`);
|
||||
|
||||
const headers = Object.keys(data[0]);
|
||||
const rows = data.map((row: { [key: string]: any }) => Object.values(row));
|
||||
const outputData = [headers, ...rows];
|
||||
|
||||
await writeDataToSheet(robotId, spreadsheetId, outputData);
|
||||
await writeDataToSheet(robotId, spreadsheetId, data);
|
||||
console.log(`Data written to Google Sheet successfully for Robot: ${robotId} and Run: ${runId}`);
|
||||
} else {
|
||||
console.log('Google Sheets integration not configured.');
|
||||
@@ -102,7 +98,43 @@ export async function writeDataToSheet(robotId: string, spreadsheetId: string, d
|
||||
|
||||
const sheets = google.sheets({ version: 'v4', auth: oauth2Client });
|
||||
|
||||
const resource = { values: data };
|
||||
const checkResponse = await sheets.spreadsheets.values.get({
|
||||
spreadsheetId,
|
||||
range: 'Sheet1!1:1',
|
||||
});
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
console.log('No data to write. Exiting early.');
|
||||
return;
|
||||
}
|
||||
|
||||
const expectedHeaders = Object.keys(data[0]);
|
||||
|
||||
const rows = data.map(item => Object.values(item));
|
||||
|
||||
const existingHeaders =
|
||||
checkResponse.data.values &&
|
||||
checkResponse.data.values[0] ?
|
||||
checkResponse.data.values[0].map(String) :
|
||||
[];
|
||||
|
||||
const isSheetEmpty = existingHeaders.length === 0;
|
||||
|
||||
const headersMatch =
|
||||
!isSheetEmpty &&
|
||||
existingHeaders.length === expectedHeaders.length &&
|
||||
expectedHeaders.every((header, index) => existingHeaders[index] === header);
|
||||
|
||||
let resource;
|
||||
|
||||
if (isSheetEmpty || !headersMatch) {
|
||||
resource = { values: [expectedHeaders, ...rows] };
|
||||
console.log('Including headers in the append operation.');
|
||||
} else {
|
||||
resource = { values: rows };
|
||||
console.log('Headers already exist and match, only appending data rows.');
|
||||
}
|
||||
|
||||
console.log('Attempting to write to spreadsheet:', spreadsheetId);
|
||||
|
||||
const response = await sheets.spreadsheets.values.append({
|
||||
|
||||
@@ -92,7 +92,7 @@ function AddGeneratedFlags(workflow: WorkflowFile) {
|
||||
return copy;
|
||||
};
|
||||
|
||||
async function executeRun(id: string) {
|
||||
async function executeRun(id: string, userId: string) {
|
||||
try {
|
||||
const run = await Run.findOne({ where: { runId: id } });
|
||||
if (!run) {
|
||||
@@ -114,7 +114,7 @@ async function executeRun(id: string) {
|
||||
|
||||
plainRun.status = 'running';
|
||||
|
||||
const browser = browserPool.getRemoteBrowser(plainRun.browserId);
|
||||
const browser = browserPool.getRemoteBrowser(userId);
|
||||
if (!browser) {
|
||||
throw new Error('Could not access browser');
|
||||
}
|
||||
@@ -132,7 +132,7 @@ async function executeRun(id: string) {
|
||||
const binaryOutputService = new BinaryOutputService('maxun-run-screenshots');
|
||||
const uploadedBinaryOutput = await binaryOutputService.uploadAndStoreBinaryOutput(run, interpretationInfo.binaryOutput);
|
||||
|
||||
await destroyRemoteBrowser(plainRun.browserId);
|
||||
await destroyRemoteBrowser(plainRun.browserId, userId);
|
||||
|
||||
await run.update({
|
||||
...run,
|
||||
@@ -207,22 +207,22 @@ async function executeRun(id: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function readyForRunHandler(browserId: string, id: string) {
|
||||
async function readyForRunHandler(browserId: string, id: string, userId: string) {
|
||||
try {
|
||||
const interpretation = await executeRun(id);
|
||||
const interpretation = await executeRun(id, userId);
|
||||
|
||||
if (interpretation) {
|
||||
logger.log('info', `Interpretation of ${id} succeeded`);
|
||||
} else {
|
||||
logger.log('error', `Interpretation of ${id} failed`);
|
||||
await destroyRemoteBrowser(browserId);
|
||||
await destroyRemoteBrowser(browserId, userId);
|
||||
}
|
||||
|
||||
resetRecordingState(browserId, id);
|
||||
|
||||
} catch (error: any) {
|
||||
logger.error(`Error during readyForRunHandler: ${error.message}`);
|
||||
await destroyRemoteBrowser(browserId);
|
||||
await destroyRemoteBrowser(browserId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,12 +245,12 @@ export async function handleRunRecording(id: string, userId: string) {
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
|
||||
socket.on('ready-for-run', () => readyForRunHandler(browserId, newRunId));
|
||||
socket.on('ready-for-run', () => readyForRunHandler(browserId, newRunId, userId));
|
||||
|
||||
logger.log('info', `Running robot: ${id}`);
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
cleanupSocketListeners(socket, browserId, newRunId);
|
||||
cleanupSocketListeners(socket, browserId, newRunId, userId);
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
@@ -258,8 +258,8 @@ export async function handleRunRecording(id: string, userId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupSocketListeners(socket: Socket, browserId: string, id: string) {
|
||||
socket.off('ready-for-run', () => readyForRunHandler(browserId, id));
|
||||
function cleanupSocketListeners(socket: Socket, browserId: string, id: string, userId: string) {
|
||||
socket.off('ready-for-run', () => readyForRunHandler(browserId, id, userId));
|
||||
logger.log('info', `Cleaned up listeners for browserId: ${browserId}, runId: ${id}`);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user