diff options
author | Frederick Muriuki Muriithi | 2024-09-05 10:26:14 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-05 10:26:29 -0500 |
commit | f5b60f2909c6683345ae0f1070e84e40c41af5ad (patch) | |
tree | b562c455ffb4567f347543f7f54a92da15acb369 /uploader/session.py | |
parent | 40dbb863ffb99721d4b736eb237ce94f15e61e48 (diff) | |
download | gn-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.py | 13 |
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) |