Skip to content

Commit 3008457

Browse files
authored
fix download client timing issue (#134)
1 parent 93ada95 commit 3008457

1 file changed

Lines changed: 42 additions & 22 deletions

File tree

modules/downloadarr/service.nix

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,27 @@ let
195195
196196
UPDATED_CLIENT=$(apply_field_overrides "$EXISTING_CLIENT" "$FIELD_OVERRIDES")
197197
198-
${
199-
mkSecureCurl serviceConfig.apiKey {
200-
url = "$BASE_URL/downloadclient/$CLIENT_ID";
201-
method = "PUT";
202-
headers = {
203-
"Content-Type" = "application/json";
204-
};
205-
data = "$UPDATED_CLIENT";
206-
extraArgs = "-Sf";
207-
}
208-
} >/dev/null
198+
for _retry_attempt in $(seq 1 5); do
199+
if ${
200+
mkSecureCurl serviceConfig.apiKey {
201+
url = "$BASE_URL/downloadclient/$CLIENT_ID";
202+
method = "PUT";
203+
headers = {
204+
"Content-Type" = "application/json";
205+
};
206+
data = "$UPDATED_CLIENT";
207+
extraArgs = "-Sf";
208+
}
209+
} >/dev/null; then
210+
break
211+
fi
212+
if [ "$_retry_attempt" -eq 5 ]; then
213+
echo "Error: Failed to update download client ${clientName} after 5 attempts"
214+
exit 1
215+
fi
216+
echo "Attempt $_retry_attempt to update ${clientName} failed, retrying in 1 second..."
217+
sleep 1
218+
done
209219
210220
echo "Download client ${clientName} updated"
211221
else
@@ -220,17 +230,27 @@ let
220230
221231
NEW_CLIENT=$(apply_field_overrides "$SCHEMA" "$FIELD_OVERRIDES")
222232
223-
${
224-
mkSecureCurl serviceConfig.apiKey {
225-
url = "$BASE_URL/downloadclient";
226-
method = "POST";
227-
headers = {
228-
"Content-Type" = "application/json";
229-
};
230-
data = "$NEW_CLIENT";
231-
extraArgs = "-Sf";
232-
}
233-
} >/dev/null
233+
for _retry_attempt in $(seq 1 5); do
234+
if ${
235+
mkSecureCurl serviceConfig.apiKey {
236+
url = "$BASE_URL/downloadclient";
237+
method = "POST";
238+
headers = {
239+
"Content-Type" = "application/json";
240+
};
241+
data = "$NEW_CLIENT";
242+
extraArgs = "-Sf";
243+
}
244+
} >/dev/null; then
245+
break
246+
fi
247+
if [ "$_retry_attempt" -eq 5 ]; then
248+
echo "Error: Failed to create download client ${clientName} after 5 attempts"
249+
exit 1
250+
fi
251+
echo "Attempt $_retry_attempt to create ${clientName} failed, retrying in 1 second..."
252+
sleep 1
253+
done
234254
235255
echo "Download client ${clientName} created"
236256
fi

0 commit comments

Comments
 (0)