feat: pass userId

This commit is contained in:
amhsirak
2025-03-05 21:27:08 +05:30
parent ba519a6a1b
commit cce663c6fd

View File

@@ -507,9 +507,9 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string) {
} }
} }
async function readyForRunHandler(browserId: string, id: string) { async function readyForRunHandler(browserId: string, id: string, userId: string){
try { try {
const result = await executeRun(id); const result = await executeRun(id, userId);
if (result && result.success) { if (result && result.success) {
logger.log('info', `Interpretation of ${id} succeeded`); logger.log('info', `Interpretation of ${id} succeeded`);
@@ -546,7 +546,7 @@ function AddGeneratedFlags(workflow: WorkflowFile) {
return copy; return copy;
}; };
async function executeRun(id: string) { async function executeRun(id: string, userId: string) {
try { try {
const run = await Run.findOne({ where: { runId: id } }); const run = await Run.findOne({ where: { runId: id } });
if (!run) { if (!run) {
@@ -568,7 +568,7 @@ async function executeRun(id: string) {
plainRun.status = 'running'; plainRun.status = 'running';
const browser = browserPool.getRemoteBrowser(plainRun.browserId); const browser = browserPool.getRemoteBrowser(plainRun.browserId, userId);
if (!browser) { if (!browser) {
throw new Error('Could not access browser'); throw new Error('Could not access browser');
} }
@@ -672,12 +672,12 @@ export async function handleRunRecording(id: string, userId: string) {
rejectUnauthorized: false 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}`); logger.log('info', `Running Robot: ${id}`);
socket.on('disconnect', () => { socket.on('disconnect', () => {
cleanupSocketListeners(socket, browserId, newRunId); cleanupSocketListeners(socket, browserId, newRunId, userId);
}); });
// Return the runId immediately, so the client knows the run is started // Return the runId immediately, so the client knows the run is started
@@ -688,8 +688,8 @@ export async function handleRunRecording(id: string, userId: string) {
} }
} }
function cleanupSocketListeners(socket: Socket, browserId: string, id: string) { function cleanupSocketListeners(socket: Socket, browserId: string, id: string, userId: string) {
socket.off('ready-for-run', () => readyForRunHandler(browserId, id)); socket.off('ready-for-run', () => readyForRunHandler(browserId, id, userId));
logger.log('info', `Cleaned up listeners for browserId: ${browserId}, runId: ${id}`); logger.log('info', `Cleaned up listeners for browserId: ${browserId}, runId: ${id}`);
} }