@@ -17,6 +17,7 @@ import {
1717 OpsEdition ,
1818 ProjectId ,
1919 RunEnvironment ,
20+ ScheduleOptions ,
2021 TriggerHookType ,
2122 TriggerType ,
2223} from '@openops/shared' ;
@@ -125,29 +126,32 @@ export const enableBlockTrigger = async (
125126 }
126127 break ;
127128 }
128- case TriggerStrategy . POLLING :
129- case TriggerStrategy . SCHEDULED : {
129+ case TriggerStrategy . POLLING : {
130130 if ( isNil ( engineHelperResponse . result . scheduleOptions ) ) {
131131 engineHelperResponse . result . scheduleOptions = {
132132 cronExpression : POLLING_FREQUENCY_CRON_EXPRESSON ,
133133 timezone : 'UTC' ,
134134 failureCount : 0 ,
135135 } ;
136136 }
137- await flowQueue . add ( {
138- executionCorrelationId : flowVersion . id ,
139- type : JobType . REPEATING ,
140- data : {
141- schemaVersion : LATEST_JOB_DATA_SCHEMA_VERSION ,
142- projectId,
143- environment : RunEnvironment . PRODUCTION ,
144- flowVersionId : flowVersion . id ,
145- flowId : flowVersion . flowId ,
146- triggerType : TriggerType . BLOCK ,
147- jobType : RepeatableJobType . EXECUTE_TRIGGER ,
148- } ,
149- scheduleOptions : engineHelperResponse . result . scheduleOptions ,
150- } ) ;
137+
138+ const scheduleOptions = engineHelperResponse . result . scheduleOptions ;
139+
140+ await addBlockTriggerToQueue ( projectId , flowVersion , scheduleOptions ) ;
141+
142+ break ;
143+ }
144+ case TriggerStrategy . SCHEDULED : {
145+ const scheduleOptions = engineHelperResponse . result . scheduleOptions ;
146+
147+ if ( isNil ( scheduleOptions ) ) {
148+ throw new Error (
149+ 'No schedule options set for trigger of Schedule type.' ,
150+ ) ;
151+ }
152+
153+ await addBlockTriggerToQueue ( projectId , flowVersion , scheduleOptions ) ;
154+
151155 break ;
152156 }
153157 }
@@ -160,3 +164,24 @@ type EnableParams = {
160164 flowVersion : FlowVersion ;
161165 simulate : boolean ;
162166} ;
167+
168+ async function addBlockTriggerToQueue (
169+ projectId : string ,
170+ flowVersion : FlowVersion ,
171+ scheduleOptions : ScheduleOptions ,
172+ ) : Promise < void > {
173+ await flowQueue . add ( {
174+ executionCorrelationId : flowVersion . id ,
175+ type : JobType . REPEATING ,
176+ data : {
177+ schemaVersion : LATEST_JOB_DATA_SCHEMA_VERSION ,
178+ projectId,
179+ environment : RunEnvironment . PRODUCTION ,
180+ flowVersionId : flowVersion . id ,
181+ flowId : flowVersion . flowId ,
182+ triggerType : TriggerType . BLOCK ,
183+ jobType : RepeatableJobType . EXECUTE_TRIGGER ,
184+ } ,
185+ scheduleOptions,
186+ } ) ;
187+ }
0 commit comments