Skip to content

Commit

Permalink
Add remote checker task
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Aug 10, 2023
1 parent ffc245c commit 21f4fd3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pydatalab/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,53 @@ def check_item_validity(_, base_url: str | None = None, starting_materials: bool
admin.add_task(check_item_validity)


@task
def check_remotes(_, base_url: str = None):
"""This task looks up all configured remotes and checks that they
can be synced.
Requires the environment variable DATALAB_API_KEY to be set.
Parameters:
base_url: The API URL.
"""

import os

import requests

api_key = os.environ.get("DATALAB_API_KEY")
if not api_key:
raise SystemExit("DATALAB_API_KEY env var not set")

log = setup_log("check_remotes")

user_response = requests.get(
f"{base_url}/get-current-user/", headers={"DATALAB-API-KEY": api_key}
)
if not user_response.status_code == 200:
raise SystemExit(f"Could not get current user: {user_response.json()['message']}")

directory_response = requests.get(
f"{base_url}/list-remote-directories/", headers={"DATALAB-API-KEY": api_key}
)

if directory_response.status_code != 200:
raise SystemExit(f"Could not get remote directories: {directory_response}")

directory_structure = directory_response.json()

for d in directory_structure:
if d["type"] == "error":
log.error(f"ꙮ {d['name']!r}: {d['details']!r}")
elif d["type"] == "toplevel":
log.info(f"✓ {d['name']!r}")


admin.add_task(check_remotes)


@task
def import_cheminventory(_, filename: str):
import random
Expand Down

0 comments on commit 21f4fd3

Please sign in to comment.