Skip to content

Commit

Permalink
Added STOPPED and CANCELLED Job States.
Browse files Browse the repository at this point in the history
Added STOPPED Flow State.
Added proper queries for jobs and flows with a STOPPED state.
  • Loading branch information
davidwaroquiers committed Aug 23, 2023
1 parent 07c20e5 commit 24d2eda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/jobflow_remote/jobs/jobcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def _build_query_wf(
}
},
]
elif state == FlowState.STOPPED:
query["fws.state"] = "DEFUSED"
else:
raise RuntimeError("Unknown flow state.")

Expand Down
13 changes: 12 additions & 1 deletion src/jobflow_remote/jobs/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class JobState(Enum):
REMOTE_ERROR = "REMOTE_ERROR"
COMPLETED = "COMPLETED"
FAILED = "FAILED"
PAUSED = "PAUSED"
PAUSED = "PAUSED" # Not yet used
STOPPED = "STOPPED"
CANCELLED = "CANCELLED" # Not yet used

@classmethod
def from_states(
Expand All @@ -66,6 +68,10 @@ def from_states(
return JobState.ONGOING
elif fw_state == "FIZZLED":
return JobState.FAILED
# When stop_jobflow or stop_children is used in Response, the Firework with
# the corresponding job is set to a DEFUSED state.
elif fw_state == "DEFUSED":
return JobState.STOPPED

raise ValueError(f"Unsupported FW state {fw_state}")

Expand All @@ -80,6 +86,8 @@ def to_states(self) -> tuple[list[str], list[RemoteState] | None]:
return ["RESERVED", "RUNNING"], [RemoteState.FAILED]
elif self == JobState.FAILED:
return ["FIZZLED"], [RemoteState.COMPLETED]
elif self == JobState.STOPPED:
return ["DEFUSED"], None

raise ValueError(f"Unhandled state {self}")

Expand All @@ -97,6 +105,7 @@ class FlowState(Enum):
COMPLETED = "COMPLETED"
FAILED = "FAILED"
PAUSED = "PAUSED"
STOPPED = "STOPPED"

@classmethod
def from_jobs_states(cls, jobs_states: list[JobState]) -> FlowState:
Expand All @@ -110,5 +119,7 @@ def from_jobs_states(cls, jobs_states: list[JobState]) -> FlowState:
return cls.FAILED
elif all(js == JobState.PAUSED for js in jobs_states):
return cls.PAUSED
elif any(js == JobState.STOPPED for js in jobs_states):
return cls.STOPPED
else:
return cls.ONGOING

0 comments on commit 24d2eda

Please sign in to comment.