Skip to content

Commit

Permalink
Merge pull request #128 from CanDIG/develop
Browse files Browse the repository at this point in the history
v4.2.1: respawn daemon if it dies
  • Loading branch information
daisieh authored Oct 10, 2024
2 parents 5e887c8 + d36e1b4 commit a4bea11
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions daemon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
until python daemon.py; do
echo "Daemon crashed with exit code $?. Respawning.." >&2
sleep 1
done
19 changes: 17 additions & 2 deletions htsget_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
def link_genomic_data(sample, do_not_index=False):
url = f"{HTSGET_URL}/ga4gh/drs/v1/objects"
result = {
"errors": []
"errors": [],
"to_index": []
}

# Use service token to authenticate this with htsget
Expand Down Expand Up @@ -137,7 +138,7 @@ def link_genomic_data(sample, do_not_index=False):
# flag the genomic_drs_object for indexing:
logger.debug(f"Are we indexing? do_not_index = {do_not_index}")
url =f"{HTSGET_URL}/htsget/v1/{sample['metadata']['data_type']}s/{genomic_drs_obj['id']}/index"
response = requests.get(url, headers=headers, params={"do_not_index": do_not_index})
result["to_index"].append(url)
return result


Expand Down Expand Up @@ -223,6 +224,7 @@ def htsget_ingest(ingest_json, do_not_index=False):
"errors": {},
"results": {}
}
to_index = []
status_code = 200
for sample in ingest_json:
logger.debug(f"Ingesting {sample['genomic_file_id']}, do_not_index = {do_not_index}")
Expand All @@ -240,8 +242,21 @@ def htsget_ingest(ingest_json, do_not_index=False):
if len(result["errors"][sample["genomic_file_id"]]) == 0:
result["errors"].pop(sample["genomic_file_id"])
response.pop("errors")
to_index.extend(response["to_index"])
if len(response) > 0:
result["results"][sample["genomic_file_id"]] = response
# Use service token to authenticate this with htsget
headers = {}
if not IS_TESTING:
headers = {
"X-Service-Token": create_service_token(),
"Content-Type": "application/json"
}

# send off index calls
for url in to_index:
response = requests.get(url, headers=headers, params={"do_not_index": do_not_index})

return result, status_code


Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
mkdir -p $DAEMON_PATH/to_ingest
mkdir -p $DAEMON_PATH/results
python /ingest_app/daemon.py &
bash /ingest_app/daemon.sh &

gunicorn server:app

0 comments on commit a4bea11

Please sign in to comment.