Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
fixd update submission status function
Browse files Browse the repository at this point in the history
  • Loading branch information
Toan Quach authored and Toan Quach committed Nov 15, 2023
1 parent b3d1143 commit 8dc1a0c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 47 deletions.
59 changes: 36 additions & 23 deletions src/taipy/core/submission/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
self.id = id or self.__new_id()
self._jobs: Union[List[Job], List[JobId], List] = jobs or []
self._creation_date = creation_date or datetime.now()
self._submission_status = submission_status or SubmissionStatus.UNDEFINED
self._submission_status = submission_status or SubmissionStatus.SUBMITTED
self._version = version or _VersionManagerFactory._build_manager()._get_latest_version()

@staticmethod
Expand Down Expand Up @@ -129,8 +129,9 @@ def __gt__(self, other):
def __ge__(self, other):
return self.creation_date.timestamp() == other.creation_date.timestamp() or self > other

def _update_submission_status(self, plop: Job):
submission_status = SubmissionStatus.UNDEFINED
def _update_submission_status(self, _: Job):
abandoned = False
canceled = False
blocked = False
pending = False
running = False
Expand All @@ -140,28 +141,40 @@ def _update_submission_status(self, plop: Job):
if not job:
continue
if job.is_failed():
submission_status = SubmissionStatus.FAILED
break
self.submission_status = SubmissionStatus.FAILED # type: ignore
return
if job.is_canceled():
submission_status = SubmissionStatus.CANCELED
break
if not blocked and job.is_blocked():
canceled = True
if job.is_blocked():
blocked = True
if not pending and job.is_pending():
continue
if job.is_pending() or job.is_submitted():
pending = True
if not running and job.is_running():
continue
if job.is_running():
running = True
if not completed and (job.is_completed() or job.is_skipped()):
continue
if job.is_completed() or job.is_skipped():
completed = True

if submission_status == SubmissionStatus.UNDEFINED:
if pending:
submission_status = SubmissionStatus.PENDING
elif blocked:
submission_status = SubmissionStatus.BLOCKED
elif running:
submission_status = SubmissionStatus.RUNNING
elif completed:
submission_status = SubmissionStatus.COMPLETED

self.submission_status = submission_status # type: ignore
continue
if job.is_abandoned():
abandoned = True
if canceled:
self.submission_status = SubmissionStatus.CANCELED # type: ignore
return
if abandoned:
self.submission_status = SubmissionStatus.UNDEFINED # type: ignore
return
if running:
self.submission_status = SubmissionStatus.RUNNING # type: ignore
return
if pending:
self.submission_status = SubmissionStatus.PENDING # type: ignore
return
if blocked:
self.submission_status = SubmissionStatus.BLOCKED # type: ignore
return
if completed:
self.submission_status = SubmissionStatus.COMPLETED # type: ignore
return
self.submission_status = SubmissionStatus.UNDEFINED # type: ignore
6 changes: 5 additions & 1 deletion src/taipy/core/submission/submission_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ class SubmissionStatus(_ReprEnum):
The possible values are:
- `UNDEFINED`: AN `UNDEFINED` submission has been created for execution but not processed yet by
- `SUBMITTED`: A `SUBMITTED` submission has been submitted for execution but not processed yet by
the orchestrator.
- `UNDEFINED`: AN `UNDEFINED` submission's jobs have been submitted for execution but got some undefined
status changes.
- `PENDING`: A `PENDING` submission has been enqueued by the orchestrator. It is waiting for an executor
to be available for its execution.
Expand All @@ -36,6 +39,7 @@ class SubmissionStatus(_ReprEnum):
- `COMPLETED`: A `COMPLETED` submission has successfully been executed.
"""

SUBMITTED = 0
UNDEFINED = 1
BLOCKED = 2
PENDING = 3
Expand Down
10 changes: 5 additions & 5 deletions tests/core/submission/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import pytest

from src.taipy.core import JobId, TaskId
from src.taipy.core import TaskId
from src.taipy.core.job._job_manager_factory import _JobManagerFactory
from src.taipy.core.job.job import Job
from src.taipy.core.job.status import Status
Expand All @@ -35,7 +35,7 @@ def test_create_submission(scenario, job, current_datetime):
assert submission_1.entity_id == scenario.id
assert submission_1.jobs == []
assert isinstance(submission_1.creation_date, datetime)
assert submission_1._submission_status == SubmissionStatus.UNDEFINED
assert submission_1._submission_status == SubmissionStatus.SUBMITTED
assert submission_1._version is not None

submission_2 = Submission(
Expand Down Expand Up @@ -139,6 +139,7 @@ def test_update_single_submission_status(job_ids, expected_submission_status):
(["job1_failed", "job6_completed"], SubmissionStatus.FAILED),
(["job1_failed", "job7_skipped"], SubmissionStatus.FAILED),
(["job1_failed", "job8_abandoned"], SubmissionStatus.FAILED),
(["job2_canceled", "job1_failed"], SubmissionStatus.FAILED),
(["job3_blocked", "job1_failed"], SubmissionStatus.FAILED),
(["job4_pending", "job1_failed"], SubmissionStatus.FAILED),
(["job5_running", "job1_failed"], SubmissionStatus.FAILED),
Expand All @@ -161,7 +162,6 @@ def test_update_submission_status_with_one_failed_job_in_jobs(job_ids, expected_
(["job2_canceled", "job6_completed"], SubmissionStatus.CANCELED),
(["job2_canceled", "job7_skipped"], SubmissionStatus.CANCELED),
(["job2_canceled", "job8_abandoned"], SubmissionStatus.CANCELED),
(["job2_canceled", "job1_failed"], SubmissionStatus.CANCELED),
(["job3_blocked", "job2_canceled"], SubmissionStatus.CANCELED),
(["job4_pending", "job2_canceled"], SubmissionStatus.CANCELED),
(["job5_running", "job2_canceled"], SubmissionStatus.CANCELED),
Expand Down Expand Up @@ -296,8 +296,8 @@ def test_auto_set_and_reload():
assert submission_2.jobs == [job_2, job_1]

# auto set & reload on submission_status attribute
assert submission_1.submission_status == SubmissionStatus.UNDEFINED
assert submission_2.submission_status == SubmissionStatus.UNDEFINED
assert submission_1.submission_status == SubmissionStatus.SUBMITTED
assert submission_2.submission_status == SubmissionStatus.SUBMITTED
submission_1.submission_status = SubmissionStatus.BLOCKED
assert submission_1.submission_status == SubmissionStatus.BLOCKED
assert submission_2.submission_status == SubmissionStatus.BLOCKED
Expand Down
2 changes: 1 addition & 1 deletion tests/core/submission/test_submission_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_create_submission(scenario):
assert submission_1.entity_id == scenario.id
assert submission_1.jobs == []
assert isinstance(submission_1.creation_date, datetime)
assert submission_1._submission_status == SubmissionStatus.UNDEFINED
assert submission_1._submission_status == SubmissionStatus.SUBMITTED


def test_get_submission():
Expand Down
18 changes: 1 addition & 17 deletions tests/core/submission/test_submission_manager_with_sql_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,12 @@
from datetime import datetime
from time import sleep

import pytest

from src.taipy.core import Task
from src.taipy.core._orchestrator._dispatcher._job_dispatcher import _JobDispatcher
from src.taipy.core._orchestrator._orchestrator_factory import _OrchestratorFactory
from src.taipy.core._repository.db._sql_session import _build_engine, _SQLSession
from src.taipy.core._version._version_manager_factory import _VersionManagerFactory
from src.taipy.core.config.job_config import JobConfig
from src.taipy.core.data import InMemoryDataNode
from src.taipy.core.data._data_manager import _DataManager
from src.taipy.core.data._data_manager_factory import _DataManagerFactory
from src.taipy.core.exceptions.exceptions import JobNotDeletedException
from src.taipy.core.job._job_manager import _JobManager
from src.taipy.core.job._job_manager_factory import _JobManagerFactory
from src.taipy.core.job.job_id import JobId
from src.taipy.core.job.status import Status
from src.taipy.core.submission._submission_manager_factory import _SubmissionManagerFactory
from src.taipy.core.submission.submission import Submission
from src.taipy.core.submission.submission_status import SubmissionStatus
from src.taipy.core.task._task_manager import _TaskManager
from src.taipy.core.task._task_manager_factory import _TaskManagerFactory
from src.taipy.core.task.task import Task


def init_managers():
Expand All @@ -56,7 +40,7 @@ def test_create_submission(scenario, init_sql_repo):
assert submission_1.entity_id == scenario.id
assert submission_1.jobs == []
assert isinstance(submission_1.creation_date, datetime)
assert submission_1._submission_status == SubmissionStatus.UNDEFINED
assert submission_1._submission_status == SubmissionStatus.SUBMITTED


def test_get_submission(init_sql_repo):
Expand Down

0 comments on commit 8dc1a0c

Please sign in to comment.