Skip to content

Commit

Permalink
fix(progress): correctly handle running and stopped jobs (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Jan 26, 2024
1 parent 9ddb488 commit 56ef6a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The list of contributors in alphabetical order:
- `Dinos Kousidis <https://orcid.org/0000-0002-4914-4289>`_
- `Jan Okraska <https://orcid.org/0000-0002-1416-3244>`_
- `Lukas Heinrich <https://orcid.org/0000-0002-4048-7584>`_
- `Marco Donadoni <https://orcid.org/0000-0003-2922-5505>`_
- `Marco Vidal <https://orcid.org/0000-0002-9363-4971>`_
- `Rokas Maciulaitis <https://orcid.org/0000-0003-1064-6967>`_
- `Sinclert Pérez <https://www.linkedin.com/in/sinclert>`_
Expand Down
4 changes: 4 additions & 0 deletions reana_workflow_engine_yadage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ class JobStatus(str, Enum):
failed = "failed"
stopped = "stopped"
queued = "queued"


JOB_TERMINAL_STATUSES = [JobStatus.finished, JobStatus.failed, JobStatus.stopped]
"""Statuses that a job can be in at the end of its execution."""
17 changes: 10 additions & 7 deletions reana_workflow_engine_yadage/externalbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
from packtivity.syncbackends import build_job, finalize_inputs, packconfig, publish
from reana_commons.api_client import JobControllerAPIClient as RJC_API_Client

from .config import LOGGING_MODULE, MOUNT_CVMFS, JobStatus, WORKFLOW_KERBEROS
from .config import (
JOB_TERMINAL_STATUSES,
LOGGING_MODULE,
MOUNT_CVMFS,
JobStatus,
WORKFLOW_KERBEROS,
)

log = logging.getLogger(LOGGING_MODULE)

Expand Down Expand Up @@ -156,11 +162,8 @@ def _refresh_job_status(self, job_id: str) -> None:
self.jobs_statuses[job_id] = self._get_job_status_from_controller(job_id)

def _should_refresh_job_status(self, job_id: str) -> bool:
if job_id in self.jobs_statuses:
status = self.jobs_statuses[job_id]
return status == JobStatus.started
else:
return True
status = self.jobs_statuses.get(job_id)
return status not in JOB_TERMINAL_STATUSES

Check warning on line 166 in reana_workflow_engine_yadage/externalbackend.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_engine_yadage/externalbackend.py#L165-L166

Added lines #L165 - L166 were not covered by tests

def _get_state(self, resultproxy: ReanaExternalProxy) -> str:
"""Get the packtivity state."""
Expand All @@ -171,7 +174,7 @@ def _get_state(self, resultproxy: ReanaExternalProxy) -> str:

def ready(self, resultproxy: ReanaExternalProxy) -> bool:
"""Check if a packtivity is finished."""
return self._get_state(resultproxy) != JobStatus.started
return self._get_state(resultproxy) in JOB_TERMINAL_STATUSES

Check warning on line 177 in reana_workflow_engine_yadage/externalbackend.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_engine_yadage/externalbackend.py#L177

Added line #L177 was not covered by tests

def successful(self, resultproxy: ReanaExternalProxy) -> bool:
"""Check if the packtivity was successful."""
Expand Down

0 comments on commit 56ef6a4

Please sign in to comment.