Skip to content

Commit

Permalink
feat!: update task status (#397)
Browse files Browse the repository at this point in the history
Signed-off-by: SdgJlbl <sarah.diot-girard@owkin.com>
Signed-off-by: Guilhem Barthés <guilhem.barthes@owkin.com>
Co-authored-by: Guilhem Barthés <guilhem.barthes@owkin.com>
  • Loading branch information
SdgJlbl and guilhem-barthes committed Feb 15, 2024
1 parent d16042f commit d67381c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- BREAKING: Renamed `function` field of the Function pydantic model to `archive`([#393](https://github.com/Substra/substra/pull/393))
- BREAKING: Renamed ComputeTask status ([#397](https://github.com/Substra/substra/pull/397))

### Added

Expand Down
6 changes: 4 additions & 2 deletions references/sdk_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ ComputePlan
- owner: <class 'str'>
- metadata: typing.Dict[str, str]
- task_count: <class 'int'>
- waiting_count: <class 'int'>
- todo_count: <class 'int'>
- waiting_builder_slot_count: <class 'int'>
- building_count: <class 'int'>
- waiting_parent_tasks_count: <class 'int'>
- waiting_executor_slot_count: <class 'int'>
- doing_count: <class 'int'>
- canceled_count: <class 'int'>
- failed_count: <class 'int'>
Expand Down
15 changes: 9 additions & 6 deletions substra/sdk/backends/local/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def __add_compute_plan(
tag="",
name=key,
task_count=task_count,
todo_count=task_count,
waiting_for_executor_slot=task_count,
metadata=dict(),
owner="local",
delete_intermediary_models=False,
Expand All @@ -243,8 +243,8 @@ def __create_compute_plan_from_task(self, spec, in_tasks):

# Add to the compute plan
compute_plan.task_count += 1
compute_plan.todo_count += 1
compute_plan.status = models.Status.waiting
compute_plan.waiting_executor_slot_count += 1
compute_plan.status = models.ComputePlanStatus.waiting

elif not spec.compute_plan_key and (spec.rank == 0 or spec.rank is None):
# Create a compute plan
Expand Down Expand Up @@ -390,8 +390,10 @@ def _add_compute_plan(self, spec: schemas.ComputePlanSpec, spec_options: dict =
status=models.ComputePlanStatus.empty,
metadata=spec.metadata or dict(),
task_count=0,
waiting_count=0,
todo_count=0,
waiting_builder_slot_count=0,
building_count=0,
waiting_parent_tasks_count=0,
waiting_executor_slot_count=0,
doing_count=0,
canceled_count=0,
failed_count=0,
Expand Down Expand Up @@ -426,7 +428,8 @@ def _add_task(self, key, spec, spec_options=None):
inputs=_schemas_list_to_models_list(spec.inputs, models.InputRef),
outputs=_output_from_spec(spec.outputs),
tag=spec.tag or "",
status=models.Status.waiting,
# TODO: the waiting status should be more granular now
status=models.Status.waiting_for_executor_slot,
metadata=spec.metadata if spec.metadata else dict(),
)

Expand Down
2 changes: 1 addition & 1 deletion substra/sdk/backends/local/compute/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _get_asset_unknown_type(self, asset_key, possible_types: List[schemas.Type])

def _update_cp(self, compute_plan: models.ComputePlan, update_live_performances: bool):
compute_plan.done_count += 1
compute_plan.todo_count -= 1
compute_plan.waiting_executor_slot_count -= 1
if compute_plan.done_count == compute_plan.task_count:
compute_plan.status = models.ComputePlanStatus.done
compute_plan.end_date = datetime.datetime.now()
Expand Down
12 changes: 8 additions & 4 deletions substra/sdk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class Status(str, enum.Enum):
"""Status of the task"""

unknown = "STATUS_UNKNOWN"
building = "STATUS_BUILDING"
doing = "STATUS_DOING"
done = "STATUS_DONE"
failed = "STATUS_FAILED"
todo = "STATUS_TODO"
waiting = "STATUS_WAITING"
waiting_for_executor_slot = "STATUS_WAITING_FOR_EXECUTOR_SLOT"
waiting_for_parent_tasks = "STATUS_WAITING_FOR_PARENT_TASKS"
waiting_for_builder_slot = "STATUS_WAITING_FOR_BUILDER_SLOT"
canceled = "STATUS_CANCELED"


Expand Down Expand Up @@ -305,8 +307,10 @@ class ComputePlan(_Model):
owner: str
metadata: Dict[str, str]
task_count: int = 0
waiting_count: int = 0
todo_count: int = 0
waiting_builder_slot_count: int = 0
building_count: int = 0
waiting_parent_tasks_count: int = 0
waiting_executor_slot_count: int = 0
doing_count: int = 0
canceled_count: int = 0
failed_count: int = 0
Expand Down
6 changes: 4 additions & 2 deletions tests/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,10 @@
"duration": "90",
"status": "PLAN_STATUS_DONE",
"task_count": 21,
"waiting_count": 1,
"todo_count": 2,
"waiting_builder_slot_count": 0,
"building_count": 0,
"waiting_parent_tasks_count": 1,
"waiting_executor_slot_count": 2,
"doing_count": 3,
"canceled_count": 4,
"failed_count": 5,
Expand Down
4 changes: 3 additions & 1 deletion tests/sdk/test_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def test_wait_task_failed(client, mocker):
@pytest.mark.parametrize(
("asset_dict", "function_name", "status"),
[
(datastore.TRAINTASK, "wait_task", Status.todo),
(datastore.TRAINTASK, "wait_task", Status.waiting_for_parent_tasks),
(datastore.TRAINTASK, "wait_task", Status.waiting_for_builder_slot),
(datastore.TRAINTASK, "wait_task", Status.waiting_for_executor_slot),
(datastore.COMPUTE_PLAN, "wait_compute_plan", ComputePlanStatus.todo),
],
ids=_param_name_maker,
Expand Down

0 comments on commit d67381c

Please sign in to comment.