@@ -23,6 +23,7 @@ import {
23
23
import { tableFromIPC } from "apache-arrow" ;
24
24
import * as http2 from "http2" ;
25
25
import type * as net from "net" ;
26
+ import { setTimeout } from "node:timers/promises" ;
26
27
27
28
// Prepare the restate server
28
29
async function prepareRestateEndpoint (
@@ -303,37 +304,46 @@ export class StateProxy<TState extends TypedState> {
303
304
entries : [ key : string , value : Uint8Array ] [ ] ,
304
305
version ?: string
305
306
) {
306
- const res = await fetch (
307
- `${ this . adminAPIBaseUrl } /services/${ this . service } /state` ,
308
- {
309
- method : "POST" ,
310
- headers : {
311
- "Content-Type" : "application/json" ,
312
- } ,
313
- body : JSON . stringify (
314
- {
315
- version,
316
- object_key : this . serviceKey ,
317
- new_state : Object . fromEntries ( entries ) ,
307
+ let lastFailure : Error | undefined = undefined ;
308
+ for ( let i = 0 ; i < 10 ; i ++ ) {
309
+ const res = await fetch (
310
+ `${ this . adminAPIBaseUrl } /services/${ this . service } /state` ,
311
+ {
312
+ method : "POST" ,
313
+ headers : {
314
+ "Content-Type" : "application/json" ,
318
315
} ,
319
- ( key , value ) => {
320
- if ( value instanceof Uint8Array ) {
321
- return Array . from ( value ) ;
322
- } else {
323
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
324
- return value ;
316
+ body : JSON . stringify (
317
+ {
318
+ version,
319
+ object_key : this . serviceKey ,
320
+ new_state : Object . fromEntries ( entries ) ,
321
+ } ,
322
+ ( key , value ) => {
323
+ if ( value instanceof Uint8Array ) {
324
+ return Array . from ( value ) ;
325
+ } else {
326
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
327
+ return value ;
328
+ }
325
329
}
326
- }
327
- ) ,
330
+ ) ,
331
+ }
332
+ ) ;
333
+
334
+ if ( res . ok ) {
335
+ return ;
328
336
}
329
- ) ;
330
337
331
- if ( ! res . ok ) {
332
338
const badResponse = await res . text ( ) ;
333
- throw new Error (
339
+ lastFailure = new Error (
334
340
`Error ${ res . status } during modify state: ${ badResponse } `
335
341
) ;
342
+
343
+ await setTimeout ( 1000 ) ;
336
344
}
345
+
346
+ throw lastFailure ;
337
347
}
338
348
}
339
349
0 commit comments