Skip to content

Commit

Permalink
fix: retry requests to vatsim api
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRomaa committed Aug 9, 2024
1 parent 67379f3 commit 482d8f3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.contrib.auth.models import PermissionsMixin
from django.db import models
from django.utils import timezone
from requests.adapters import HTTPAdapter, Retry

from apps.mailer.models import Email
from zhu_core.utils import OverwriteStorage, base26decode, base26encode, rating_int_to_short
Expand Down Expand Up @@ -244,7 +245,18 @@ def update_loa_status(self):
self.save()

def update_rating(self):
vatsim_data = requests.get(f"https://api.vatsim.net/api/ratings/{self.cid}").json()
session = requests.Session()
session.mount(
"https://",
HTTPAdapter(
max_retries=Retry(
total=3,
backoff_factor=0.1,
status_forcelist=[500, 502, 503, 504],
)
)
)
vatsim_data = session.get(f"https://api.vatsim.net/api/ratings/{self.cid}").json()

if rating_short := rating_int_to_short(vatsim_data.get("rating")):
self.rating = rating_short
Expand Down

0 comments on commit 482d8f3

Please sign in to comment.