feat: add logic to update workflow on save

This commit is contained in:
Rohit
2025-04-09 20:46:38 +05:30
parent 389a1cbdc8
commit 962723b87f

View File

@@ -139,12 +139,14 @@ export class WorkflowGenerator {
*/ */
private registerEventHandlers = (socket: Socket) => { private registerEventHandlers = (socket: Socket) => {
socket.on('save', (data) => { socket.on('save', (data) => {
const { fileName, userId, isLogin } = data; const { fileName, userId, isLogin, robotId } = data;
logger.log('debug', `Saving workflow ${fileName} for user ID ${userId}`); logger.log('debug', `Saving workflow ${fileName} for user ID ${userId}`);
this.saveNewWorkflow(fileName, userId, isLogin); this.saveNewWorkflow(fileName, userId, isLogin, robotId);
}); });
socket.on('new-recording', () => this.workflowRecord = { socket.on('new-recording', (data) => {
this.workflowRecord = {
workflow: [], workflow: [],
};
}); });
socket.on('activeIndex', (data) => this.generatedData.lastIndex = parseInt(data)); socket.on('activeIndex', (data) => this.generatedData.lastIndex = parseInt(data));
socket.on('decision', async ({ pair, actionType, decision, userId }) => { socket.on('decision', async ({ pair, actionType, decision, userId }) => {
@@ -764,9 +766,26 @@ export class WorkflowGenerator {
* @param fileName The name of the file. * @param fileName The name of the file.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public saveNewWorkflow = async (fileName: string, userId: number, isLogin: boolean) => { public saveNewWorkflow = async (fileName: string, userId: number, isLogin: boolean, robotId?: string) => {
const recording = this.optimizeWorkflow(this.workflowRecord); const recording = this.optimizeWorkflow(this.workflowRecord);
try { try {
if (robotId) {
const robot = await Robot.findOne({ where: { 'recording_meta.id': robotId }});
if (robot) {
await robot.update({
recording: recording,
recording_meta: {
...robot.recording_meta,
pairs: recording.workflow.length,
params: this.getParams() || [],
updatedAt: new Date().toLocaleString(),
},
})
logger.log('info', `Robot retrained with id: ${robot.id}`);
}
} else {
this.recordingMeta = { this.recordingMeta = {
name: fileName, name: fileName,
id: uuid(), id: uuid(),
@@ -791,6 +810,7 @@ export class WorkflowGenerator {
logger.log('info', `Robot saved with id: ${robot.id}`); logger.log('info', `Robot saved with id: ${robot.id}`);
} }
}
catch (e) { catch (e) {
const { message } = e as Error; const { message } = e as Error;
logger.log('warn', `Cannot save the file to the local file system ${e}`) logger.log('warn', `Cannot save the file to the local file system ${e}`)