@@ -11,15 +11,22 @@ export type CheckpointClientOptions = {
1111 apiUrl : URL ;
1212 workerClient : SupervisorHttpClient ;
1313 orchestrator : CheckpointType ;
14+ timeoutMs ?: number ;
15+ restoreTimeoutMs ?: number ;
1416} ;
1517
16- const CANCEL_TIMEOUT_MS = 5_000 ;
18+ const DEFAULT_TIMEOUT_MS = 5_000 ;
19+ const DEFAULT_RESTORE_TIMEOUT_MS = 30_000 ;
1720
1821export class CheckpointClient {
1922 private readonly logger = new SimpleStructuredLogger ( "checkpoint-client" ) ;
2023
2124 constructor ( private readonly opts : CheckpointClientOptions ) { }
2225
26+ private timeout ( ms = this . opts . timeoutMs ?? DEFAULT_TIMEOUT_MS ) : AbortSignal {
27+ return AbortSignal . timeout ( ms ) ;
28+ }
29+
2330 async suspendRun ( {
2431 runFriendlyId,
2532 snapshotFriendlyId,
@@ -43,6 +50,7 @@ export class CheckpointClient {
4350 type : this . opts . orchestrator ,
4451 ...body ,
4552 } satisfies CheckpointServiceSuspendRequestBodyInput ) ,
53+ signal : this . timeout ( ) ,
4654 }
4755 ) ;
4856
@@ -107,6 +115,7 @@ export class CheckpointClient {
107115 "Content-Type" : "application/json" ,
108116 } ,
109117 body : JSON . stringify ( body ) ,
118+ signal : this . timeout ( this . opts . restoreTimeoutMs ?? DEFAULT_RESTORE_TIMEOUT_MS ) ,
110119 }
111120 ) ;
112121
@@ -146,6 +155,7 @@ export class CheckpointClient {
146155 "Content-Type" : "application/json" ,
147156 } ,
148157 body : JSON . stringify ( body ) ,
158+ signal : this . timeout ( ) ,
149159 }
150160 ) ;
151161
@@ -160,19 +170,14 @@ export class CheckpointClient {
160170 return true ;
161171 }
162172
163- /**
164- * cancelCheckpoints returns "unsupported" when the route is absent, which is expected while a
165- * newer caller runs against an older checkpoint service. The route answers 202 even when the run
166- * has nothing in flight, so a 404 only ever means the route itself is missing.
167- */
168173 async cancelCheckpoints ( {
169174 runFriendlyId,
170175 } : {
171176 runFriendlyId : string ;
172177 } ) : Promise < "ok" | "unsupported" | "failed" > {
173178 const res = await fetch (
174179 new URL ( `/api/v1/runs/${ runFriendlyId } /checkpoints/cancel` , this . opts . apiUrl ) ,
175- { method : "POST" , signal : AbortSignal . timeout ( CANCEL_TIMEOUT_MS ) }
180+ { method : "POST" , signal : this . timeout ( ) }
176181 ) ;
177182
178183 if ( res . status === 404 ) {
0 commit comments