StoredWorkflow model represents a workflow instance in the database. It stores the workflow’s class, arguments, output, and execution status.
Database Table
Table:workflows
Model Attributes
Primary key for the workflow instance
Fully qualified class name of the workflow (e.g.,
App\Workflows\MyWorkflow)Serialized workflow arguments passed during workflow creation
Serialized output/result of the workflow execution
Current status of the workflow. Possible values:
pending- Workflow is queued for executionrunning- Workflow is currently executingcompleted- Workflow finished successfullyfailed- Workflow encountered an errorcontinued- Workflow has been continued with ContinueAsNew
pendingWhen the workflow was created (microsecond precision)
When the workflow was last updated (microsecond precision)
Relationships
logs()
Returns all activity execution logs for this workflow, ordered by ID.HasMany relationship to StoredWorkflowLog
exceptions()
Returns all exceptions that occurred during workflow execution.HasMany relationship to StoredWorkflowException
signals()
Returns all signals sent to this workflow.HasMany relationship to StoredWorkflowSignal
timers()
Returns all timers created by this workflow.HasMany relationship to StoredWorkflowTimer
parents()
Returns parent workflows that spawned this workflow as a child.BelongsToMany relationship to StoredWorkflow
Pivot fields:
parent_index- The activity index in the parent workflowparent_now- The timestamp when the child was created
children()
Returns child workflows spawned by this workflow.BelongsToMany relationship to StoredWorkflow
Pivot fields:
parent_index- The activity index in the parent workflowparent_now- The timestamp when the child was created
continuedWorkflows()
Returns workflows that were created via ContinueAsNew from this workflow.BelongsToMany relationship to StoredWorkflow where parent_index equals StoredWorkflow::CONTINUE_PARENT_INDEX
activeWorkflow()
Returns the current active workflow in a continuation chain.BelongsToMany relationship to StoredWorkflow where parent_index equals StoredWorkflow::ACTIVE_WORKFLOW_INDEX
Important Methods
toWorkflow()
Converts the stored workflow back into aWorkflowStub instance.
workflowMetadata()
Returns the workflow metadata containing arguments and options.workflowArguments()
Returns the unserialized workflow arguments.workflowOptions()
Returns the workflow execution options.effectiveConnection()
Returns the queue connection that should be used for this workflow.effectiveQueue()
Returns the queue name that should be used for this workflow.findLogByIndex()
Finds a log entry by its index number.$index- The activity index to find$fresh- Whether to query the database instead of using loaded relations
null if not found
hasLogByIndex()
Checks if a log entry exists for a given index.createLog()
Creates a new log entry for this workflow.findTimerByIndex()
Finds a timer by its index number.createTimer()
Creates a new timer for this workflow.orderedSignals()
Returns signals ordered by creation time.active()
Returns the currently active workflow instance. If the workflow has been continued, returns the continuation.prunable()
Defines which workflows are eligible for automatic pruning.- Have status
completed - Were created before the configured
prune_age(default: 1 month) - Have no parent workflows
Querying Workflow History
Get all completed workflows
Get workflow with all logs
Get workflow with exceptions
Get workflows by class
Get child workflows
Get workflow continuation chain
Find the active workflow in a continuation chain
Configuration
The model class can be customized inconfig/workflows.php:
Constants
Special parent index value (
PHP_INT_MAX) used to mark workflow continuation relationshipsSpecial parent index value (
PHP_INT_MAX - 1) used to mark the active workflow in a continuation chainTraits
- HasStates - Provides state management functionality for workflow status
- Prunable - Enables automatic cleanup of old completed workflows
See Also
- StoredWorkflowLog - Activity execution logs
- StoredWorkflowException - Workflow exceptions
- WorkflowStub - Workflow instance interface