import { State } from '../state' ; export const delayRetryState = < S extends State > ( state , errorMessage , /** How many times to retry a step that fails */ maxRetryAttempts ) : S => { if ( state . retryCount >= maxRetryAttempts ) { return { ... state , controlState : 'FATAL' , reason : `Unable to complete the ${ state . controlState } step after ${ maxRetryAttempts } attempts, terminating.` , } ; } else { const retryCount = state . retryCount + 1 ; const retryDelay = 1000 * Math . min ( Math . pow ( 2 , retryCount ) , 64 ) ; return { ... state , retryCount , retryDelay , logs : [ ... state . logs , { level : 'error' , message : `Action failed with '${ errorMessage }'. Retrying attempt ${ retryCount } in ${ retryDelay / 1000 } seconds.` , } , ] , } ; } } ; export const resetRetryState = < S extends State > ( state ) : S => { return { ... state , retryCount : 0 , retryDelay : 0 , } ; } ;