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 c55f15c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@
"error": {
"type": "string",
"title": "Error",
"description": "If the task status result is `False` shows an error message"
"description": "Error message"
},
"status": {
"type": "boolean",
Expand Down 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
11 changes: 3 additions & 8 deletions repository_service_tuf_api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,9 @@ class GetParameters(BaseModel):

class TaskResult(BaseModel):
message: Optional[str] = Field(description="Result detail description")
error: Optional[str] = Field(
description=(
"If the task status result is `False` shows an error message"
)
)
error: Optional[str] = Field(description="Error message")
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 +61,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 +131,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
4 changes: 3 additions & 1 deletion 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 @@ -82,7 +83,7 @@ def test_get_result_is_exception(self, test_client, monkeypatch):
"task_id": "test_id",
"state": "FAILURE",
"result": {
"message": "Task failure: Failed to load",
"message": "Failed to load",
},
},
"message": "Task state.",
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 c55f15c

Please sign in to comment.