import { proxyActivities , uuid4 } from '@temporalio/workflow' ; import type { createStickyActivities , createNonStickyActivities } from './activities' ; const { getUniqueTaskQueue } = proxyActivities < ReturnType < typeof createNonStickyActivities > > ( { startToCloseTimeout : '1 minute' , } ) ; export async function fileProcessingWorkflow ( maxAttempts = 5 ) { for ( let attempt = 1 ; attempt <= maxAttempts ; ++ attempt ) { try { const uniqueWorkerTaskQueue = await getUniqueTaskQueue ( ) ; const activities = proxyActivities < ReturnType < typeof createStickyActivities > > ( { taskQueue : uniqueWorkerTaskQueue , scheduleToCloseTimeout : '1 minute' , } ) ; const downloadPath = `/tmp/${ uuid4 ( ) }` ; await activities . downloadFileToWorkerFileSystem ( 'https://temporal.io' , downloadPath ) ; try { await activities . workOnFileInWorkerFileSystem ( downloadPath ) ; } finally { await activities . cleanupFileFromWorkerFileSystem ( downloadPath ) ; } return ; } catch ( err ) { if ( attempt === maxAttempts ) { console . log ( `Final attempt (${ attempt }) failed, giving up` ) ; throw err ; } console . log ( `Attempt ${ attempt } failed, retrying on a new Worker` ) ; } } }