aboutsummaryrefslogtreecommitdiff
path: root/uploader/session.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-05 10:26:14 -0500
committerFrederick Muriuki Muriithi2024-09-05 10:26:29 -0500
commitf5b60f2909c6683345ae0f1070e84e40c41af5ad (patch)
treeb562c455ffb4567f347543f7f54a92da15acb369 /uploader/session.py
parent40dbb863ffb99721d4b736eb237ce94f15e61e48 (diff)
downloadgn-uploader-f5b60f2909c6683345ae0f1070e84e40c41af5ad.tar.gz
Synchronise token refreshing.
When running flask with multiple threads/workers, as happens when using gunicorn, there is a potential for more than one thread running with an expired token, leading to multiple uncoordinated token refreshes. This commit coordinates the threads in the case there is need to refresh a token, ensuring only one thread does the token refresh.
Diffstat (limited to 'uploader/session.py')
-rw-r--r--uploader/session.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/uploader/session.py b/uploader/session.py
index 019d959..399f28c 100644
--- a/uploader/session.py
+++ b/uploader/session.py
@@ -103,3 +103,16 @@ def set_auth_server_jwks(keyset: KeySet) -> KeySet:
}
})
return keyset
+
+
+def toggle_token_refreshing():
+ """Toggle the state of the token_refreshing variable."""
+ _session = session_info()
+ return save_session_info({
+ **_session,
+ "token_refreshing": not _session.get("token_refreshing", False)})
+
+
+def is_token_refreshing():
+ """Returns whether the token is being refreshed or not."""
+ return session_info().get("token_refreshing", False)