Skip to content
Snippets Groups Projects
Commit e413a4c6 authored by Tim Kreuzer's avatar Tim Kreuzer
Browse files

add pre poll function

parent 059c5401
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import json ...@@ -4,6 +4,7 @@ import json
import os import os
import random import random
import re import re
import time
from datetime import datetime from datetime import datetime
from datefinder import find_dates from datefinder import find_dates
...@@ -459,6 +460,34 @@ def custom_port(spawner, user_options): ...@@ -459,6 +460,34 @@ def custom_port(spawner, user_options):
return port return port
async def pre_poll_hook(spawner):
custom_config = get_custom_config()
system = spawner.user_options.get("system", "")
backend_service = (
custom_config.get("systems", {}).get(system, {}).get("backendService", "None")
)
if (
custom_config.get("backendServices", {})
.get(backend_service, {})
.get("pollAccessTokenRequired", False)
):
# If we know we need need the access token to perform a valid poll request,
# let's avoid the call to the Outpost if it's not helpful anyway.
user = spawner.user
auth_state = await user.get_auth_state()
if not auth_state:
return False
threshold = 2 * user.authenticator.true_auth_refresh_age
now = time.time()
rest_time = int(auth_state.get("exp", now)) - now
if not auth_state.get("access_token", None) or threshold > rest_time:
spawner.log.info(
f"{spawner._log_name} - Do not call Outpost for polling (access_token available: {bool(auth_state.get('acccess_token'))}, rest_time: {rest_time}"
)
return False
return True
async def pre_spawn_hook(spawner): async def pre_spawn_hook(spawner):
custom_config = get_custom_config() custom_config = get_custom_config()
service, version = spawner.user_options.get("profile", "").split("/") service, version = spawner.user_options.get("profile", "").split("/")
......
...@@ -31,6 +31,7 @@ dependencies = [ ...@@ -31,6 +31,7 @@ dependencies = [
"urllib3", "urllib3",
"pyyaml", "pyyaml",
"jupyterhub-unicorespawner", "jupyterhub-unicorespawner",
"jupyterhub-forwardbasespawner>=1.0.8",
"jupyterhub-outpostspawner", "jupyterhub-outpostspawner",
"oauthenticator" "oauthenticator"
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment