Skip to content

Commit

Permalink
fixup! fixup! fix: API docs Task and improve consistency
Browse files Browse the repository at this point in the history
Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com>
  • Loading branch information
kairoaraujo committed Feb 7, 2024
1 parent ddd900a commit 92a8408
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@
"$ref": "#/components/schemas/TaskState"
}
],
"description": "The Celery task state. Note: It isn't the task result status.\n\n`PENDING`: Task state is unknown (assumed pending since you know the id).\n\n`RECEIVED`: Task received by a RSTUF Worker (only used in events).\n\n`SUCCESS`: Task succeeded.\n\n`STARTED`: Task started by a RSTUF Worker.\n\n`RUNNING`: Task is running on RSTUF Worker.\n\n`FAILURE`: Task failed (unexpected).\n\n`REVOKED`: Task revoked.\n\n`RETRY`: Task is waiting for retry.\n\n`ERRORED`: Task errored. RSTUF identified an error while processing the task.\n\n`REJECTED`: Task was rejected (only used in events).\n\n`IGNORED`: Task was ignored."
"description": "The Celery task state.\n\n`PENDING`: Task state is unknown (assumed pending since you know the id).\n\n`RECEIVED`: Task received by a RSTUF Worker (only used in events).\n\n`SUCCESS`: Task succeeded.\n\n`STARTED`: Task started by a RSTUF Worker.\n\n`RUNNING`: Task is running on RSTUF Worker.\n\n`FAILURE`: Task failed (unexpected).\n\n`REVOKED`: Task revoked.\n\n`RETRY`: Task is waiting for retry.\n\n`ERRORED`: Task errored. RSTUF identified an error while processing the task.\n\n`REJECTED`: Task was rejected (only used in events).\n\n`IGNORED`: Task was ignored."
},
"result": {
"allOf": [
Expand Down
5 changes: 2 additions & 3 deletions repository_service_tuf_api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class TaskResult(BaseModel):
)
status: Optional[bool] = Field(
description="Task result status. `True` Success | `False` Failure",
exclude=True,
)
task: Optional[TaskName] = Field(description="Task name by worker")
last_update: Optional[datetime] = Field(
Expand All @@ -66,7 +65,7 @@ class TasksData(BaseModel):
task_id: str = Field(description="Task ID")
state: TaskState = Field(
description=(
"The Celery task state. Note: It isn't the task result status.\n\n"
"The Celery task state.\n\n"
"`PENDING`: Task state is unknown (assumed pending since you know "
"the id).\n\n"
"`RECEIVED`: Task received by a RSTUF Worker (only used in "
Expand Down Expand Up @@ -136,7 +135,7 @@ def get(task_id: str) -> Response:
# and default message as critical failure executing the task.
if isinstance(task.result, Exception):
task_result = {
"message": f"Task failure: {str(task.result)}",
"message": {str(task.result)},
}

# If the task state is SUCCESS and the task result is False we considere
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_get(self, test_client, monkeypatch):
"task": "add_targets",
"last_update": "2023-11-17T09:54:15.762882",
"message": "Target(s) Added",
"status": True,
"details": {
"targets": [
"file1.tar.gz",
Expand Down Expand Up @@ -122,6 +123,7 @@ def test_get_result_is_errored(self, test_client, monkeypatch):
"task": "sign_metadata",
"last_update": "2023-11-17T09:54:15.762882",
"message": "Signature Failed",
"status": False,
"error": "No signatures pending for root",
},
},
Expand Down

0 comments on commit 92a8408

Please sign in to comment.