From 03e55aa4cb38b0778f827794f02c46a725fdb702 Mon Sep 17 00:00:00 2001 From: Md Asif Raza Date: Thu, 9 Oct 2025 00:47:35 +0530 Subject: [PATCH 1/4] fix: cron expression on edit --- .../workspace/services/testflow.service.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/modules/workspace/services/testflow.service.ts b/src/modules/workspace/services/testflow.service.ts index 4768573d9..3cb9fef40 100644 --- a/src/modules/workspace/services/testflow.service.ts +++ b/src/modules/workspace/services/testflow.service.ts @@ -170,6 +170,18 @@ export class TestflowService implements OnModuleInit { ); environmentName = environmentData?.name || ""; } + let cronExpression; + if(updateScheduleDto.runConfiguration){ + const runCycleConfig = this.buildRunCycleConfig(updateScheduleDto.runConfiguration); + cronExpression = this.generateCronExpression(runCycleConfig); + if (!cronExpression) { + updateScheduleDto.cronExpression = null; + } + else{ + updateScheduleDto.cronExpression = cronExpression; + } + } + // Merge update fields, ensure id is present const updatedSchedular: TestflowSchedular = { ...existingSchedular, @@ -187,7 +199,6 @@ export class TestflowService implements OnModuleInit { ); // Optionally update cron job if runConfiguration or isActive changed if ( - updateScheduleDto.runConfiguration || updateScheduleDto.isActive !== undefined ) { const schedular = await this.testflowRepository.getSchedularById( @@ -202,9 +213,7 @@ export class TestflowService implements OnModuleInit { const runCycleConfig = this.buildRunCycleConfig( schedular.runConfiguration, ); - const cronExpression = - schedular.cronExpression || - this.generateCronExpression(runCycleConfig); + const cronExpression = schedular.cronExpression; await this.testflowSchedulerService.addSchedulerJob( runCycleConfig, this.getScheduledExecutionCallback( From 3e40503a305041fa053095f760963d815f56b906 Mon Sep 17 00:00:00 2001 From: Md Asif Raza Date: Thu, 9 Oct 2025 01:01:07 +0530 Subject: [PATCH 2/4] fix: cron expression on edit --- src/modules/workspace/services/testflow.service.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/workspace/services/testflow.service.ts b/src/modules/workspace/services/testflow.service.ts index 3cb9fef40..ab8364058 100644 --- a/src/modules/workspace/services/testflow.service.ts +++ b/src/modules/workspace/services/testflow.service.ts @@ -197,7 +197,7 @@ export class TestflowService implements OnModuleInit { scheduleId, updatedSchedular, ); - // Optionally update cron job if runConfiguration or isActive changed + // Optionally update cron job if isActive changed if ( updateScheduleDto.isActive !== undefined ) { @@ -383,6 +383,16 @@ export class TestflowService implements OnModuleInit { id, user._id, ); + + // Remove all associated cronjobs for this testflow + if (testflow?.schedules && Array.isArray(testflow.schedules)) { + for (const schedule of testflow.schedules) { + if (schedule?.id) { + await this.testflowSchedulerService.removeSchedulerJob(schedule.id); + } + } + } + const updateMessage = `"${testflow.name}" testflow is deleted from "${workspace.name}" workspace`; const currentWorkspaceObject = new ObjectId(workspaceId); const updateWorkspaceData: Partial = { From 0f8f274b50a70d2c873e91b4f3611c26df828e3a Mon Sep 17 00:00:00 2001 From: Md Asif Raza Date: Thu, 9 Oct 2025 01:10:50 +0530 Subject: [PATCH 3/4] fix: testflow cron job configurations --- .../workspace/services/testflow.service.ts | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/modules/workspace/services/testflow.service.ts b/src/modules/workspace/services/testflow.service.ts index ab8364058..c93ccd6c3 100644 --- a/src/modules/workspace/services/testflow.service.ts +++ b/src/modules/workspace/services/testflow.service.ts @@ -197,39 +197,36 @@ export class TestflowService implements OnModuleInit { scheduleId, updatedSchedular, ); - // Optionally update cron job if isActive changed - if ( - updateScheduleDto.isActive !== undefined - ) { - const schedular = await this.testflowRepository.getSchedularById( - testflowId, - scheduleId, - ); - if (schedular) { - // Remove old job - await this.testflowSchedulerService.removeSchedulerJob(scheduleId); - // If still active, re-add job - if (schedular.isActive) { - const runCycleConfig = this.buildRunCycleConfig( - schedular.runConfiguration, - ); - const cronExpression = schedular.cronExpression; - await this.testflowSchedulerService.addSchedulerJob( - runCycleConfig, - this.getScheduledExecutionCallback( - testflowId, - schedular.environmentId, - workspaceId, - scheduleId, - user, - ), - schedular.schedularName, - cronExpression, + + const schedular = await this.testflowRepository.getSchedularById( + testflowId, + scheduleId, + ); + if (schedular) { + // Remove old job + await this.testflowSchedulerService.removeSchedulerJob(scheduleId); + // If still active, re-add job + if (schedular.isActive) { + const runCycleConfig = this.buildRunCycleConfig( + schedular.runConfiguration, + ); + const cronExpression = schedular.cronExpression; + await this.testflowSchedulerService.addSchedulerJob( + runCycleConfig, + this.getScheduledExecutionCallback( + testflowId, + schedular.environmentId, + workspaceId, scheduleId, - ); - } + user, + ), + schedular.schedularName, + cronExpression, + scheduleId, + ); } } + return result; } From 524e1d4af40d1a275d70cfa430aaab86188fe1fc Mon Sep 17 00:00:00 2001 From: Md Asif Raza Date: Thu, 9 Oct 2025 01:14:35 +0530 Subject: [PATCH 4/4] fix: testflow cron job configurations --- src/modules/workspace/services/testflow.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/workspace/services/testflow.service.ts b/src/modules/workspace/services/testflow.service.ts index c93ccd6c3..b5833778a 100644 --- a/src/modules/workspace/services/testflow.service.ts +++ b/src/modules/workspace/services/testflow.service.ts @@ -170,10 +170,10 @@ export class TestflowService implements OnModuleInit { ); environmentName = environmentData?.name || ""; } - let cronExpression; + if(updateScheduleDto.runConfiguration){ const runCycleConfig = this.buildRunCycleConfig(updateScheduleDto.runConfiguration); - cronExpression = this.generateCronExpression(runCycleConfig); + const cronExpression = this.generateCronExpression(runCycleConfig); if (!cronExpression) { updateScheduleDto.cronExpression = null; }