Replies: 2 comments 2 replies
-
Q1: Is Laravel Workflow suitable for our architectural approach? ✅ Yes! Laravel Workflow supports parallel execution, event-driven state management, and dynamic workflow control via signals and queries. Your architecture fits well. Q2: Is our proposed state machine approach valid? ✅ Yes! There is a detailed blog post about using state machines with Laravel Workflow at https://laravel-workflow.com/blog/combining-laravel-workflow-and-state-machines/ Q3: Is there a better way to handle dynamic input updates? ✅ You can use signals to update the workflow and an await to prevent the workflow from progressing until all the require fields are set. https://laravel-workflow.com/docs/features/signal+timer Q4: How can we prevent workflows from getting stuck? ✅ Use timeouts and limit retries. You can also listen for workflow events to add your own monitoring in the case of failures. |
Beta Was this translation helpful? Give feedback.
-
It seems that library has diverged and is no longer compatible. It is also barely maintained. There is a finite state machine contained within the tests that you could repurpose and use. It is tested with every release so it is sure to work.
Taken from https://github.com/laravel-workflow/laravel-workflow/blob/master/tests/Fixtures/StateMachine.php I will work on adding this officially to the package. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am currently developing a web application for job matching and am considering transitioning from a traditional synchronous, sequential program structure to a parallel, asynchronous microservices architecture.
System Design Goals:
Instead of calling dependent sub-functions within a main function, we aim to loosely couple independent single-function programs (tasks) via workflows.
(Ultimately, we want to enable low-code/no-code system development by allowing non-engineers to define workflows.)
To ensure task independence and non-interdependency, input and output data between tasks and workflows will be handled as external variables via an external database.
Workflows should support parallel execution and parent-child relationships, enabling inter-task coordination.
Common tasks and workflows should be reusable by simply modifying input/output variables.
For example, "displaying an input form" and "registering input data" should function as reusable components that only differ in variable handling.
I would like to confirm whether Laravel Workflow can support this architectural approach.
To start, I have some questions based on a simplified example of a user registration workflow.
1): Overview of the Desired Workflow
The user sequentially enters the following information: "Name," "Gender," "Age," "Hourly Rate," and "Hobbies."
Some fields, such as "Hobbies," are optional and do not require input.
Users can skip certain fields (leave them blank and proceed) and edit fields later if needed.
In the final confirmation screen, the system should allow registration only if all required fields (Name, Gender, Age, Hourly Rate) are completed.
If any required fields are missing, the system should display an error message and allow the user to go back and fill in missing fields.
The workflow should support pausing and resuming, ensuring that users can continue registration even after an interruption.
2): Key Design Requirements and Possible Implementation Approaches
I would like to confirm whether Laravel Workflow is suitable for the following requirements, or if there is a better approach.
2-1) Workflow State Management
Requirement:
The workflow should track the user's progress and manage states such as "In Progress," "Incomplete," "Ready to Register," and "Completed."
Registration should not proceed until all required fields are completed; if any required fields are missing, the state should remain "Incomplete."
If the user modifies any input fields later, the workflow should re-evaluate the state to determine if registration is now possible.
Proposed Implementation Approach:
We assume that a state machine (finite state machine, FSM) is the best way to manage these transitions.
The following state transitions might be appropriate:
2-2) Handling Skipped and Editable Inputs
Requirement:
Users should be able to edit previously entered fields at any time, even after submission.
Since Laravel Workflow appears to enforce immutable workflow data, a mechanism is needed to dynamically update input values while keeping the workflow state intact.
To maintain a clear separation of concerns, the workflow should manage state transitions while input data should be stored in an external database.
Proposed Implementation Approach:
Store input data in the database instead of within the workflow.
Trigger state reevaluation when input data is modified.
Use workflow_can() to check whether the state should change upon data updates.
2-3) Preventing Zombie Workflows (Monitoring and Controlling Unfinished Tasks)
Requirement:
Ensure that workflows do not remain indefinitely incomplete due to unprocessed tasks.
Implement a mechanism to automatically terminate workflows that remain in an incomplete state for too long.
Prevent workflows from getting stuck due to parallel tasks failing to complete.
Proposed Implementation Approach:
We are considering the following three preventive measures:
Timeout-based auto-cancellation:
If a workflow remains incomplete for too long, it should be automatically canceled.
Job monitoring:
Detect unfinished tasks that have been running for an extended period and generate alerts.
Retry mechanism for failed tasks:
Automatically retry tasks that fail during execution.
Job::dispatch()->onQueue('default')->retryAfter(10);
3): Final Questions
Given our architectural approach and requirements, are the proposed design and implementation methods appropriate for Laravel Workflow?
If not, what alternative methods would you recommend?
I appreciate your time and insights. Looking forward to your guidance!
Best regards,
Beta Was this translation helpful? Give feedback.
All reactions