Replies: 2 comments 1 reply
-
Based on your scenario, you would use signals and queries, combined with Laravel's own event listeners.
First, setup event listeners in your Laravel app to listen for the events like "start_processing", "success", "failed" sent by the external service.
Define SignalMethods in your workflow to handle the states "in processing", "success", or "failed". This allows you to externally inform your workflow about the status of a particular activity based on events from the external service.
When your Laravel event listener receives an event from the external service, you can then signal the workflow:
Implement QueryMethods in your workflow to allow querying the status of individual activities or the overall workflow.
The workflow can continuously check the status of its activities and decide whether to move forward, wait, or terminate based on the reported statuses.
When the external service returns data with an event, your event listener can store this data in your Laravel app's database, or even signal the workflow to save it as part of the workflow's state.
At each step, after setting the status of an activity, the workflow can check all its activities to determine its overall status (whether it should proceed to the next activity, terminate, or continue waiting).
If an activity reports a "failed" status, the workflow can initiate error-handling procedures, such as retries, logging, notifications, or even termination of the workflow. For asynchronous activities that should proceed only after a "success" status from a prior activity, you can use the WorkflowStub::await() method to pause execution until the required condition is met.
|
Beta Was this translation helpful? Give feedback.
-
Hi @rmcdaniel, Thank you the reply, i implemented the way you suggested and it works like a charm. |
Beta Was this translation helpful? Give feedback.
-
Hi guys,
I have the following scenario:
I use an external service to handle jobs for my application and listen for events like "start_processing", "success", "failed" if the job is in one of the states.
To send a job to the service i use something like ($workflowData is going to be used to identify the workflow id and activity):
The code above would be executed from an activity.
The service receives the command, start processing and send an event back to the application with the data sent initially ($workflowData) and the state (in this case, "processing")
After the job is processed of failed, another event is sent to the application with the same initial data ($workflowData) and the state ("success" of "failed")
How can i load the workflow and mark the activity as "in processing", "success" or "failed" and based on workflow_id and activity name which would be unique in the workflow.
The idea would be to go to the next activity if the previous activity is marked as "success" by the external service (for async activities).
The workflow status would be "success" if all activities are marked as "success" by the service, "fail" if one of the activity failed (and don't move forward with the rest of the activities) or "wait" if the workflow didn't start or one or more activities are in progress.
Also, some of the jobs return some data which needs to be saved into the model tied to the workflow.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions