Skip to content

Commit

Permalink
Log time it takes to refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
gmertes committed Jul 5, 2024
1 parent 04f90d5 commit 47d7e69
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/anemoi/training/diagnostics/mlflow/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import requests
from anemoi.utils.config import load_config
from anemoi.utils.config import save_config
from anemoi.utils.timer import Timer
from requests.exceptions import HTTPError

from anemoi.training.utils.logger import get_code_logger
Expand Down Expand Up @@ -140,16 +141,15 @@ def authenticate(self, **kwargs):
if not self.refresh_token or self.refresh_expires < time.time():
raise RuntimeError("You are not logged in to MLflow. Please log in first.")

response = self._token_request()
with Timer("Access token refreshed", self.log):
response = self._token_request()

self.access_token = response.get("access_token")
self.access_expires = time.time() + (response.get("expires_in") * 0.7) # bit of buffer
self.refresh_token = response.get("refresh_token")

os.environ["MLFLOW_TRACKING_TOKEN"] = self.access_token

self.log.debug("Access token refreshed.")

@enabled
def save(self, **kwargs):
"""Save the latest refresh token to disk."""
Expand Down

0 comments on commit 47d7e69

Please sign in to comment.