@@ -13,8 +13,8 @@ import type { OtlpTraceService } from "../services/otlpTraceService.js";
1313import { tryCatch } from "@trigger.dev/core" ;
1414import { encodeBaggage , fromContext } from "../wideEvents/index.js" ;
1515
16- const CREATE_MAX_ATTEMPTS = 3 ;
17- const CREATE_RETRY_BASE_DELAY_MS = 250 ;
16+ const DEFAULT_CREATE_MAX_ATTEMPTS = 3 ;
17+ const DEFAULT_CREATE_RETRY_BASE_DELAY_MS = 250 ;
1818
1919/**
2020 * TEMPORARY (TRI-10293): a failed create can leave its instance name
@@ -76,13 +76,23 @@ type ComputeWorkloadManagerOptions = WorkloadManagerOptions & {
7676 otelEndpoint : string ;
7777 prettyLogs : boolean ;
7878 } ;
79+ createRetry ?: {
80+ maxAttempts : number ;
81+ baseDelayMs : number ;
82+ } ;
7983} ;
8084
8185export class ComputeWorkloadManager implements WorkloadManager {
8286 private readonly logger = new SimpleStructuredLogger ( "compute-workload-manager" ) ;
8387 private readonly compute : ComputeClient ;
88+ private readonly createMaxAttempts : number ;
89+ private readonly createRetryBaseDelayMs : number ;
8490
8591 constructor ( private opts : ComputeWorkloadManagerOptions ) {
92+ this . createMaxAttempts = opts . createRetry ?. maxAttempts ?? DEFAULT_CREATE_MAX_ATTEMPTS ;
93+ this . createRetryBaseDelayMs =
94+ opts . createRetry ?. baseDelayMs ?? DEFAULT_CREATE_RETRY_BASE_DELAY_MS ;
95+
8696 if ( opts . workloadApiDomain ) {
8797 this . logger . warn ( "⚠️ Custom workload API domain" , {
8898 domain : opts . workloadApiDomain ,
@@ -239,7 +249,7 @@ export class ComputeWorkloadManager implements WorkloadManager {
239249 // Set after a ComputeClientError: the failed create may have left its
240250 // name registered, so subsequent attempts use a suffixed name.
241251 let suffixAttempts = false ;
242- for ( ; attempt <= CREATE_MAX_ATTEMPTS ; attempt ++ ) {
252+ for ( ; attempt <= this . createMaxAttempts ; attempt ++ ) {
243253 const attemptRunnerId = suffixAttempts
244254 ? runnerNameForAttempt ( runnerId , attempt )
245255 : runnerId ;
@@ -270,8 +280,8 @@ export class ComputeWorkloadManager implements WorkloadManager {
270280 error : error instanceof Error ? error . message : String ( error ) ,
271281 } ) ;
272282
273- if ( ! isRetryableCreateError ( error ) || attempt === CREATE_MAX_ATTEMPTS ) break ;
274- await sleep ( CREATE_RETRY_BASE_DELAY_MS * attempt ) ;
283+ if ( ! isRetryableCreateError ( error ) || attempt === this . createMaxAttempts ) break ;
284+ await sleep ( this . createRetryBaseDelayMs * attempt ) ;
275285 }
276286 event . createAttempts = attempt ;
277287
0 commit comments