|
|
|
@ -23,12 +23,109 @@ class WorkflowType(StrEnum):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkflowExecutionStatus(StrEnum):
|
|
|
|
class WorkflowExecutionStatus(StrEnum):
|
|
|
|
|
|
|
|
# State diagram for the workflw status:
|
|
|
|
|
|
|
|
# (@) means start, (*) means end
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ┌------------------>------------------------->------------------->--------------┐
|
|
|
|
|
|
|
|
# | |
|
|
|
|
|
|
|
|
# | ┌-----------------------<--------------------┐ |
|
|
|
|
|
|
|
|
# ^ | | |
|
|
|
|
|
|
|
|
# | | ^ |
|
|
|
|
|
|
|
|
# | V | |
|
|
|
|
|
|
|
|
# ┌-----------┐ ┌-----------------------┐ ┌-----------┐ V
|
|
|
|
|
|
|
|
# | Scheduled |------->| Running |---------------------->| Suspended | |
|
|
|
|
|
|
|
|
# └-----------┘ └-----------------------┘ └-----------┘ |
|
|
|
|
|
|
|
|
# | | | | | | |
|
|
|
|
|
|
|
|
# | | | | | | |
|
|
|
|
|
|
|
|
# ^ | | | V V |
|
|
|
|
|
|
|
|
# | | | | | ┌---------┐ |
|
|
|
|
|
|
|
|
# (@) | | | └------------------------>| Stopped |<----┘
|
|
|
|
|
|
|
|
# | | | └---------┘
|
|
|
|
|
|
|
|
# | | | |
|
|
|
|
|
|
|
|
# | | V V
|
|
|
|
|
|
|
|
# | | ┌-----------┐ |
|
|
|
|
|
|
|
|
# | | | Succeeded |------------->--------------┤
|
|
|
|
|
|
|
|
# | | └-----------┘ |
|
|
|
|
|
|
|
|
# | V V
|
|
|
|
|
|
|
|
# | +--------┐ |
|
|
|
|
|
|
|
|
# | | Failed |---------------------->----------------┤
|
|
|
|
|
|
|
|
# | └--------┘ |
|
|
|
|
|
|
|
|
# V V
|
|
|
|
|
|
|
|
# ┌---------------------┐ |
|
|
|
|
|
|
|
|
# | Partially Succeeded |---------------------->-----------------┘--------> (*)
|
|
|
|
|
|
|
|
# └---------------------┘
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Mermaid diagram:
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ---
|
|
|
|
|
|
|
|
# title: State diagram for Workflow run state
|
|
|
|
|
|
|
|
# ---
|
|
|
|
|
|
|
|
# stateDiagram-v2
|
|
|
|
|
|
|
|
# scheduled: Scheduled
|
|
|
|
|
|
|
|
# running: Running
|
|
|
|
|
|
|
|
# succeeded: Succeeded
|
|
|
|
|
|
|
|
# failed: Failed
|
|
|
|
|
|
|
|
# partial_succeeded: Partial Succeeded
|
|
|
|
|
|
|
|
# suspended: Suspended
|
|
|
|
|
|
|
|
# stopped: Stopped
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# [*] --> scheduled:
|
|
|
|
|
|
|
|
# scheduled --> running: Start Execution
|
|
|
|
|
|
|
|
# running --> suspended: Human input required
|
|
|
|
|
|
|
|
# suspended --> running: human input added
|
|
|
|
|
|
|
|
# suspended --> stopped: User stops execution
|
|
|
|
|
|
|
|
# running --> succeeded: Execution finishes without any error
|
|
|
|
|
|
|
|
# running --> failed: Execution finishes with errors
|
|
|
|
|
|
|
|
# running --> stopped: User stops execution
|
|
|
|
|
|
|
|
# running --> partial_succeeded: some execution occurred and handled during execution
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# scheduled --> stopped: User stops execution
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# succeeded --> [*]
|
|
|
|
|
|
|
|
# failed --> [*]
|
|
|
|
|
|
|
|
# partial_succeeded --> [*]
|
|
|
|
|
|
|
|
# stopped --> [*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# `SCHEDULED` means that the workflow is scheduled to run, but has not
|
|
|
|
|
|
|
|
# started running yet. (maybe due to possible worker saturation.)
|
|
|
|
|
|
|
|
SCHEDULED = "scheduled"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# `RUNNING` means the workflow is exeuting.
|
|
|
|
RUNNING = "running"
|
|
|
|
RUNNING = "running"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# `SUCCEEDED` means the execution of workflow succeed without any error.
|
|
|
|
SUCCEEDED = "succeeded"
|
|
|
|
SUCCEEDED = "succeeded"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# `FAILED` means the execution of workflow failed without some errors.
|
|
|
|
FAILED = "failed"
|
|
|
|
FAILED = "failed"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# `STOPPED` means the execution of workflow was stopped, either manually
|
|
|
|
|
|
|
|
# by the user, or automatically by the Dify application (E.G. the moderation
|
|
|
|
|
|
|
|
# mechanism.)
|
|
|
|
STOPPED = "stopped"
|
|
|
|
STOPPED = "stopped"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# `PARTIAL_SUCCEEDED` indicates that some errors occurred during the workflow
|
|
|
|
|
|
|
|
# execution, but they were successfully handled (e.g., by using an error
|
|
|
|
|
|
|
|
# strategy such as "fail branch" or "default value").
|
|
|
|
PARTIAL_SUCCEEDED = "partial-succeeded"
|
|
|
|
PARTIAL_SUCCEEDED = "partial-succeeded"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# `SUSPENDED` indicates that the workflow execution is temporarily paused
|
|
|
|
|
|
|
|
# (e.g., awaiting human input) and is expected to resume later.
|
|
|
|
|
|
|
|
SUSPENDED = "suspended"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_ended(self) -> bool:
|
|
|
|
|
|
|
|
return self in _END_STATE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_END_STATE = frozenset(
|
|
|
|
|
|
|
|
[
|
|
|
|
|
|
|
|
WorkflowExecutionStatus.SUCCEEDED,
|
|
|
|
|
|
|
|
WorkflowExecutionStatus.FAILED,
|
|
|
|
|
|
|
|
WorkflowExecutionStatus.PARTIAL_SUCCEEDED,
|
|
|
|
|
|
|
|
WorkflowExecutionStatus.STOPPED,
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkflowExecution(BaseModel):
|
|
|
|
class WorkflowExecution(BaseModel):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|