@@ -109,7 +109,7 @@ export class RunJob {
109109 } ) ;
110110
111111 // Update workflow run delivery lifecycle after job cancellation
112- await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . COMPLETED ) ;
112+ await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . COMPLETED , undefined ) ;
113113
114114 return ;
115115 }
@@ -152,6 +152,9 @@ export class RunJob {
152152 throw new PlatformException ( `Notification with id ${ job . _notificationId } not found` ) ;
153153 }
154154
155+ const workflow =
156+ ( await this . notificationTemplateRepository . findById ( job . _templateId , job . _environmentId ) ) ?? undefined ;
157+
155158 if ( isSubscribersScheduleEnabled ) {
156159 const schedule = await this . getSubscriberSchedule . execute (
157160 GetSubscriberScheduleCommand . create ( {
@@ -177,7 +180,7 @@ export class RunJob {
177180
178181 if (
179182 isOutsideSubscriberSchedule &&
180- ( await this . shouldExtendToSubscriberSchedule ( job , notification . critical ?? false ) )
183+ ( await this . shouldExtendToSubscriberSchedule ( job , notification . critical ?? false , workflow ) )
181184 ) {
182185 this . logger . info (
183186 {
@@ -227,7 +230,7 @@ export class RunJob {
227230 ) ;
228231
229232 // Update workflow run delivery lifecycle after schedule-based cancellation
230- await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . COMPLETED ) ;
233+ await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . COMPLETED , workflow ) ;
231234
232235 return ;
233236 }
@@ -271,6 +274,7 @@ export class RunJob {
271274 severity : notification . severity ,
272275 statelessPreferences : job . preferences ,
273276 contextKeys : job . contextKeys ,
277+ workflow,
274278 } )
275279 ) ;
276280
@@ -285,7 +289,7 @@ export class RunJob {
285289 } ) ;
286290
287291 // Update workflow run delivery lifecycle after successful step completion
288- await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . PROCESSING ) ;
292+ await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . PROCESSING , workflow ) ;
289293 } else if ( sendMessageResult . status === 'failed' ) {
290294 await this . jobRepository . update (
291295 {
@@ -307,7 +311,7 @@ export class RunJob {
307311 } ) ;
308312
309313 // Update workflow run delivery lifecycle after step failure
310- await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . COMPLETED ) ;
314+ await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . COMPLETED , workflow ) ;
311315
312316 if ( shouldHaltOnStepFailure ( job ) ) {
313317 shouldQueueNextJob = false ;
@@ -330,7 +334,7 @@ export class RunJob {
330334 } ) ;
331335
332336 // Update workflow run delivery lifecycle after step skip/cancellation
333- await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . PROCESSING ) ;
337+ await this . conditionallyUpdateDeliveryLifecycle ( job , WorkflowRunStatusEnum . PROCESSING , workflow ) ;
334338 }
335339 } catch ( caughtError : unknown ) {
336340 error = caughtError as Error ;
@@ -446,7 +450,7 @@ export class RunJob {
446450 ) ;
447451
448452 // Update workflow run delivery lifecycle after step skip
449- await this . conditionallyUpdateDeliveryLifecycle ( nextJob , WorkflowRunStatusEnum . PROCESSING ) ;
453+ await this . conditionallyUpdateDeliveryLifecycle ( nextJob , WorkflowRunStatusEnum . PROCESSING , undefined ) ;
450454
451455 currentJob = nextJob ; // if skipped, continue to the next job
452456 } else {
@@ -654,7 +658,8 @@ export class RunJob {
654658 */
655659 private async conditionallyUpdateDeliveryLifecycle (
656660 job : JobEntity ,
657- workflowStatus : WorkflowRunStatusEnum
661+ workflowStatus : WorkflowRunStatusEnum ,
662+ workflow ?: NotificationTemplateEntity
658663 ) : Promise < void > {
659664 this . logger . debug ( { nv : { job } } , 'Conditionally updating delivery lifecycle' ) ;
660665
@@ -668,19 +673,21 @@ export class RunJob {
668673 return ;
669674 }
670675
671- const workflow : SelectedWorkflowFields | null = await this . notificationTemplateRepository . findOne (
672- {
673- _id : job . _templateId ,
674- _environmentId : job . _environmentId ,
675- } ,
676- SELECTED_WORKFLOW_FIELDS_PROJECTION
677- ) ;
676+ const workflowWithSteps : SelectedWorkflowFields | null =
677+ workflow ??
678+ ( await this . notificationTemplateRepository . findOne (
679+ {
680+ _id : job . _templateId ,
681+ _environmentId : job . _environmentId ,
682+ } ,
683+ SELECTED_WORKFLOW_FIELDS_PROJECTION
684+ ) ) ;
678685
679- if ( ! workflow || ! workflow . steps ) {
686+ if ( ! workflowWithSteps || ! workflowWithSteps . steps ) {
680687 return ;
681688 }
682689
683- const isLastStep = await this . isLastStepInWorkflow ( job , workflow ) ;
690+ const isLastStep = await this . isLastStepInWorkflow ( job , workflowWithSteps ) ;
684691 if ( isLastStep ) {
685692 this . logger . trace (
686693 { nv : { jobId : job . _id , stepId : job . step ?. _id } } ,
@@ -689,7 +696,7 @@ export class RunJob {
689696 return ;
690697 }
691698
692- const hasActionSteps = await this . hasRemainingActionSteps ( job , workflow ) ;
699+ const hasActionSteps = await this . hasRemainingActionSteps ( job , workflowWithSteps ) ;
693700
694701 if ( hasActionSteps ) {
695702 this . logger . trace (
@@ -724,7 +731,11 @@ export class RunJob {
724731 return false ;
725732 }
726733
727- private async shouldExtendToSubscriberSchedule ( job : JobEntity , critical : boolean ) : Promise < boolean > {
734+ private async shouldExtendToSubscriberSchedule (
735+ job : JobEntity ,
736+ critical : boolean ,
737+ workflow ?: NotificationTemplateEntity
738+ ) : Promise < boolean > {
728739 // should only extend to schedule for delay and digest when the workflow is not critical
729740 if ( ( job . type === StepTypeEnum . DELAY || job . type === StepTypeEnum . DIGEST ) && ! critical ) {
730741 const bridgeResponse = await this . executeBridgeJob . execute (
@@ -736,6 +747,7 @@ export class RunJob {
736747 jobId : job . _id ,
737748 job : job ,
738749 variables : { } ,
750+ workflow,
739751 } )
740752 ) ;
741753 const extendToSchedule = bridgeResponse ?. outputs ?. extendToSchedule as boolean | undefined ;
0 commit comments