Skip to content

Commit

Permalink
Add extra check for response code fetching last_versions (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov authored Nov 28, 2024
1 parent 4eaa6b1 commit 050aa59
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ jobs:
steps:
- uses: neuroinformatics-unit/actions/check_manifest@v2

get-week-number:
runs-on: ubuntu-latest
outputs:
WEEK_NUMBER: ${{ steps.get-week-number.outputs.WEEK_NUMBER }}
steps:
- name: Get week number
id: get-week-number
run: echo "WEEK_NUMBER=$(date -u '+%V')" >> "$GITHUB_OUTPUT"

test:
needs: [linting, manifest]
needs: [linting, manifest, get-week-number]
name: ${{ matrix.os }} py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -43,12 +52,16 @@ jobs:

steps:
- name: Cache atlases
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: | # ensure we don't cache any interrupted atlas download and extraction, if e.g. we cancel the workflow manually
~/.brainglobe
!~/.brainglobe/atlas.tar.gz
key: brainglobe
key: brainglobe-${{ runner.os }}-${{ needs.get-week-number.outputs.WEEK_NUMBER }}
restore-keys: |
brainglobe-${{ runner.os }}-${{ needs.get-week-number.outputs.WEEK_NUMBER }}
brainglobe-${{ runner.os }}-
brainglobe
- uses: neuroinformatics-unit/actions/test@v2
with:
Expand Down
24 changes: 22 additions & 2 deletions brainglobe_atlasapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import re
from pathlib import Path
from time import sleep
from typing import Callable, Optional

import requests
Expand Down Expand Up @@ -302,10 +303,29 @@ def conf_from_url(url) -> configparser.ConfigParser:
conf object
"""
text = requests.get(url).text
cache_path: Path = config.get_brainglobe_dir() / "last_versions.conf"

result = requests.get(url)
max_tries = 5
sleep_time = 0.25

while max_tries > 0 and result.status_code != 200:
result = requests.get(url)
max_tries -= 1
sleep(sleep_time)
sleep_time *= 2

if result.status_code != 200:
print(
f"Could not fetch the latest atlas versions: {result.status_code}"
)
print(f"Using the last cached version from {cache_path}")

return conf_from_file(cache_path)

text = result.text
config_obj = configparser.ConfigParser()
config_obj.read_string(text)
cache_path: Path = config.get_brainglobe_dir() / "last_versions.conf"

try:
if not cache_path.parent.exists():
Expand Down

0 comments on commit 050aa59

Please sign in to comment.