@@ -135,6 +135,8 @@ defmodule FLAME.FlyBackend do
135
135
runner_node_name: nil ,
136
136
log: nil
137
137
138
+ @ retry 10
139
+
138
140
@ valid_opts [
139
141
:app ,
140
142
:region ,
@@ -253,7 +255,7 @@ defmodule FLAME.FlyBackend do
253
255
def remote_boot ( % FlyBackend { parent_ref: parent_ref } = state ) do
254
256
{ resp , req_connect_time } =
255
257
with_elapsed_ms ( fn ->
256
- http_post! ( "#{ state . host } /v1/apps/#{ state . app } /machines" ,
258
+ http_post! ( "#{ state . host } /v1/apps/#{ state . app } /machines" , @ retry ,
257
259
content_type: "application/json" ,
258
260
headers: [
259
261
{ "Content-Type" , "application/json" } ,
@@ -333,7 +335,7 @@ defmodule FLAME.FlyBackend do
333
335
|> binary_part ( 0 , len )
334
336
end
335
337
336
- defp http_post! ( url , opts ) do
338
+ defp http_post! ( url , remaining_tries , opts ) do
337
339
Keyword . validate! ( opts , [ :headers , :body , :connect_timeout , :content_type ] )
338
340
339
341
headers =
@@ -362,6 +364,10 @@ defmodule FLAME.FlyBackend do
362
364
{ :ok , { { _ , 200 , _ } , _ , response_body } } ->
363
365
JSON . decode! ( response_body )
364
366
367
+ { :ok , { { _ , 429 , _ } , _ , _response_body } } when remaining_tries > 0 ->
368
+ Process . sleep ( 1000 )
369
+ http_post! ( url , remaining_tries - 1 , opts )
370
+
365
371
{ :ok , { { _ , status , reason } , _ , resp_body } } ->
366
372
raise "failed POST #{ url } with #{ inspect ( status ) } (#{ inspect ( reason ) } ): #{ inspect ( resp_body ) } #{ inspect ( headers ) } "
367
373
0 commit comments