Skip to content

Commit

Permalink
Change state name
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosribas committed Jul 1, 2024
1 parent 8c8ee3b commit 9a463ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def download_file(task_id: str, data_type: str):
logger.info(f"Task ID not found: {task_id}")
raise HTTPException(status_code=404, detail="Task ID not found")

elif result.state == "PROGRESS":
elif result.state == "RUNNING":
progress_ids = result.info.get("progress_ids", 0)
content = {
"task_id": task_id,
Expand Down
18 changes: 9 additions & 9 deletions app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ def fetch_data_from_search_index(self, api_url: str, data_type: str):
# update progress bar
if data_type == "json":
self.update_state(
state="PROGRESS",
state="RUNNING",
meta={"progress_ids": progress_ids, "progress_db_data": 0}
)
elif data_type == "fasta":
self.update_state(
state="PROGRESS",
state="RUNNING",
meta={"progress_ids": progress_ids, "progress_fasta": 0}
)
else:
self.update_state(
state="PROGRESS",
state="RUNNING",
meta={"progress_ids": progress_ids}
)

Expand All @@ -99,7 +99,7 @@ def fetch_data_from_search_index(self, api_url: str, data_type: str):
os.makedirs(os.path.dirname(ids_file_path), exist_ok=True)
with gzip.open(ids_file_path, "wt", encoding="utf-8") as gz_file:
gz_file.write("\n".join(ids))
self.update_state(state="PROGRESS", meta={"progress_ids": 100})
self.update_state(state="RUNNING", meta={"progress_ids": 100})
logger.info(f"Data export finished for: {self.request.id}")
return {"ids_file_path": ids_file_path}

Expand All @@ -110,7 +110,7 @@ def fetch_data_from_search_index(self, api_url: str, data_type: str):
os.makedirs(os.path.dirname(file_path), exist_ok=True)
total_ids = len(ids)
self.update_state(
state="PROGRESS",
state="RUNNING",
meta={"progress_ids": 100, "progress_db_data": 0}
)

Expand All @@ -125,7 +125,7 @@ def fetch_data_from_search_index(self, api_url: str, data_type: str):
gz_file.write(json.dumps(batch_data, default=str))
progress_db_data = int((i + batch_size) / total_ids * 100)
self.update_state(
state="PROGRESS",
state="RUNNING",
meta={
"progress_ids": 100,
"progress_db_data": progress_db_data
Expand All @@ -140,15 +140,15 @@ def fetch_data_from_search_index(self, api_url: str, data_type: str):
temp_ids_file = f"/srv/results/{self.request.id}.txt"
fasta_file_path = f"/srv/results/{self.request.id}.fasta.gz"
self.update_state(
state="PROGRESS",
state="RUNNING",
meta={"progress_ids": 100, "progress_fasta": 0}
)

with open(temp_ids_file, "w") as ids_file:
ids_file.write("\n".join(ids))

self.update_state(
state="PROGRESS",
state="RUNNING",
meta={"progress_ids": 100, "progress_fasta": 50}
)

Expand All @@ -169,7 +169,7 @@ def fetch_data_from_search_index(self, api_url: str, data_type: str):
stderr=process.stderr
)
self.update_state(
state="PROGRESS",
state="RUNNING",
meta={"progress_ids": 100, "progress_fasta": 100}
)
except sub.CalledProcessError as e:
Expand Down
4 changes: 2 additions & 2 deletions app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_download_file_processing(mocker):


def test_download_file_progress(mocker):
mock_result = Mock(state="PROGRESS")
mock_result = Mock(state="RUNNING")
mock_result.info = {"progress_ids": 50, "progress_db_data": 0}
mocker.patch.object(
fetch_data_from_search_index,
Expand All @@ -160,7 +160,7 @@ def test_download_file_progress(mocker):
assert response.status_code == 200
assert response.json() == {
"task_id": "mock-task-id",
"state": "PROGRESS",
"state": "RUNNING",
"progress_ids": 50,
"progress_db_data": 0
}

0 comments on commit 9a463ad

Please sign in to comment.