Skip to content

Commit

Permalink
chore(routes): better comments and docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Oct 27, 2024
1 parent d299e1e commit 6ad8135
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/celery.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
# Run celery
# Run celery for development
poetry run celery --app sketch_map_tool.tasks worker --concurrency 1 --beat --loglevel=INFO
2 changes: 1 addition & 1 deletion sketch_map_tool/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def zip_(results: list[tuple[str, str, BytesIO]]) -> BytesIO:


def extract_errors(async_result: AsyncResult | GroupResult) -> list[str]:
"""Extract known/custom exceptions propagated by Celery a Task or Group.
"""Extract known/custom exceptions propagated by a Celery task or group.
raises: Exception if error is not a custom exception.
"""
Expand Down
7 changes: 5 additions & 2 deletions sketch_map_tool/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ def digitize_results_post(lang="en") -> Response:
)
)
async_result_raster = group(tasks_raster).apply_async()
async_result = chord(
c = chord(
group(tasks_vector),
cleanup_blobs.signature(
kwargs={"file_ids": list(set(file_ids))},
immutable=True,
),
).apply_async()
async_result_vector = async_result.parent
async_result_vector = c.parent

# group results have to be saved for them to be able to be restored later
async_result_raster.save()
Expand Down Expand Up @@ -254,6 +254,7 @@ def status(uuid: str, type_: REQUEST_TYPES, lang="en") -> Response:
id_ = db_client_flask.get_async_result_id(uuid, type_)

# due to legacy support it is not possible to check only `type_`
# (in the past every Celery result was of type `AsyncResult`)
async_result = celery_app.GroupResult.restore(id_)
if async_result is None:
async_result = celery_app.AsyncResult(id_)
Expand Down Expand Up @@ -283,6 +284,7 @@ def status(uuid: str, type_: REQUEST_TYPES, lang="en") -> Response:
status = async_result.status
info = {"current": 0, "total": 1}
elif isinstance(async_result, GroupResult):
# `GroupResult` has no `status` attribute
results = async_result.results
if any(r.status == "STARTED" or r.ready() for r in results): # type: ignore
status = "STARTED"
Expand Down Expand Up @@ -316,6 +318,7 @@ def download(uuid: str, type_: REQUEST_TYPES, lang="en") -> Response:
id_ = db_client_flask.get_async_result_id(uuid, type_)

# due to legacy support it is not possible to check only `type_`
# (in the past every Celery result was of type `AsyncResult`)
async_result = celery_app.GroupResult.restore(id_)
if async_result is None:
async_result = celery_app.AsyncResult(id_)
Expand Down

0 comments on commit 6ad8135

Please sign in to comment.