From fcd08fcc321ea0bd716d766f31f6be50496bdc2b Mon Sep 17 00:00:00 2001 From: Serious-senpai <57554044+Serious-senpai@users.noreply.github.com> Date: Sun, 22 Dec 2024 15:11:40 +0700 Subject: [PATCH] Implement exponential backoff retry --- app/resident_manager/lib/src/state.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/resident_manager/lib/src/state.dart b/app/resident_manager/lib/src/state.dart index 4f4a769..abde5b4 100644 --- a/app/resident_manager/lib/src/state.dart +++ b/app/resident_manager/lib/src/state.dart @@ -179,7 +179,8 @@ class ApplicationState { Map? queryParameters, Map? headers, bool authorize = true, - int retry = 3, + int retry = 5, + Duration retryWait = const Duration(milliseconds: 200), }) async { headers ??= {}; if (authorize) { @@ -192,12 +193,14 @@ class ApplicationState { ); if (retry > 0 && response.statusCode >= 400 && await _reauthorize(response)) { + await Future.delayed(retryWait); return await get( path, queryParameters: queryParameters, headers: headers, authorize: authorize, retry: retry - 1, + retryWait: retryWait * 2, ); } @@ -211,7 +214,8 @@ class ApplicationState { Object? body, Encoding? encoding, bool authorize = true, - int retry = 3, + int retry = 5, + Duration retryWait = const Duration(milliseconds: 200), }) async { headers ??= {}; if (authorize) { @@ -226,6 +230,7 @@ class ApplicationState { ); if (retry > 0 && response.statusCode >= 400 && await _reauthorize(response)) { + await Future.delayed(retryWait); return await post( path, queryParameters: queryParameters, @@ -234,6 +239,7 @@ class ApplicationState { encoding: encoding, authorize: authorize, retry: retry - 1, + retryWait: retryWait * 2, ); }