@@ -4,6 +4,7 @@ import type { WorkflowQueueInternal } from './types'
44import { setTimeout } from 'node:timers/promises'
55import pRetry from 'p-retry'
66import { deserialize , serialize } from './serializer'
7+ import { Settings } from './settings'
78import { runWithTracing } from './tracer'
89
910export type WorkflowStepData =
@@ -48,13 +49,22 @@ export class WorkflowStep {
4849 const name = this . addNamePrefix ( stepName )
4950
5051 const stepData = await this . getStepData ( 'do' , name )
51- if ( stepData && 'result' in stepData ) return stepData . result as R
52+ if ( stepData && 'result' in stepData ) {
53+ Settings . logger ?. debug ?.(
54+ `[${ this . workflowId } /${ this . workflowJobId } ] Step '${ name } ' already completed, returning cached result` ,
55+ )
56+ return stepData . result as R
57+ }
5258
5359 const initialAttempt = stepData ?. attempt ?? 0
5460 await this . updateStepData ( name , {
5561 type : 'do' ,
5662 attempt : initialAttempt ,
5763 } )
64+
65+ Settings . logger ?. debug ?.(
66+ `[${ this . workflowId } /${ this . workflowJobId } ] Running step '${ name } ' (attempt ${ initialAttempt + 1 } )` ,
67+ )
5868 return pRetry (
5969 async ( attempt ) => {
6070 const result = await runWithTracing (
@@ -85,12 +95,20 @@ export class WorkflowStep {
8595 attempt : initialAttempt + attempt ,
8696 } )
8797
98+ Settings . logger ?. debug ?.(
99+ `[${ this . workflowId } /${ this . workflowJobId } ] Completed step '${ name } '` ,
100+ )
101+
88102 return result
89103 } ,
90104 {
91105 ...options ?. retry ,
92106 retries : Math . max ( ( options ?. retry ?. retries ?? 0 ) - initialAttempt , 0 ) ,
93107 onFailedAttempt : async ( ctx ) => {
108+ Settings . logger ?. debug ?.(
109+ `[${ this . workflowId } /${ this . workflowJobId } ] Step '${ name } ' error:` ,
110+ ctx . error ,
111+ )
94112 await this . updateStepData ( name , {
95113 type : 'do' ,
96114 attempt : initialAttempt + ctx . attemptNumber ,
@@ -125,6 +143,9 @@ export class WorkflowStep {
125143 } ,
126144 } ,
127145 async ( ) => {
146+ Settings . logger ?. debug ?.(
147+ `[${ this . workflowId } /${ this . workflowJobId } ] Waiting in step '${ name } ' for ${ durationMs } ms` ,
148+ )
128149 const remainingMs = Math . max ( 0 , stepData . startedAt + stepData . durationMs - now )
129150 await setTimeout ( remainingMs )
130151 } ,
0 commit comments