Stuck in await after running two activities in parallel. #276
-
|
Hey all! I'm trying out this package and got stuck trying to continue a workflow after using parallel activities and then using WorkflowStub::await to wait for approval for the two activities that ran previously. Here is my workflow: class MyWorkflow extends Workflow
{
protected $approval1 = false;
protected $approval2 = false;
protected $approval3 = false;
protected $approval4 = false;
#[SignalMethod]
public function setApproval1($approval1)
{
$this->approval1 = $approval1;
}
#[SignalMethod]
public function setApproval2($approval2)
{
$this->approval2 = $approval2;
}
#[SignalMethod]
public function setApproval3($approval3)
{
$this->approval3 = $approval3;
}
#[SignalMethod]
public function setApproval4($approval4)
{
$this->approval4 = $approval4;
}
public function execute()
{
yield ActivityStub::make(CreateApprovalRequest1::class);
yield WorkflowStub::await(fn() => $this->approval1);
yield ActivityStub::all([
ActivityStub::make(CreateApprovalRequest2::class),
ActivityStub::make(CreateApprovalRequest3::class),
]);
yield WorkflowStub::await(fn() => $this->approval2 && $this->approval3);
yield ActivityStub::make(CreateApprovalRequest4::class);
yield WorkflowStub::await(fn() => $this->approval4);
Log::info("done");
return "success";
}
}Each of my activities is just a logger that writes: "creating approval request for {RequestNumber}". Like this: class CreateApprovalRequest1 extends Activity
{
public function execute()
{
Log::info("creating approval request for 1");
}
}I run the signal methods using buttons on a Livewire component. The first signaling works flawlessly and both 2 and 3 work when ran sequentially. Only when they are ran in parallel will CreateApprovalRequest4 not execute. Any ideas as to what I'm doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
|
After staring at the screen for hours and finally deciding to write a post, a couple of minutes later I found a solution. I ran CreateApprovalRequest2 and 3 sequentially (as all those do, is write to log and in the future save some models in the database I realized there is no need for them to run in parallel) and it worked. Still I'm curious if what I was trying to do is possible. |
Beta Was this translation helpful? Give feedback.
-
|
Yep, what you were trying to do is absolutely possible with Laravel Workflow: you can run activities 2 & 3 in parallel and then Your workflow is conceptually fine: yield ActivityStub::all([
ActivityStub::make(CreateApprovalRequest2::class),
ActivityStub::make(CreateApprovalRequest3::class),
]);
yield WorkflowStub::await(fn () => $this->approval2 && $this->approval3);
yield ActivityStub::make(CreateApprovalRequest4::class);There’s nothing in the engine that forbids that pattern. In fact, this is exactly the kind of “parallel + then wait on external signals” scenario the library is designed for. Here are the most likely culprits and how I’d sanity-check them. 1. Make sure the workflow actually resumes after both parallel activities finish
yield ActivityStub::all([...]);If no workflow worker is running (or it’s on a different connection/queue), you’ll see:
Check:
Why you only see it with parallel: with sequential activities, the workflow is replayed between each activity anyway, so if your worker state is slightly off, it can look like it’s working while actually failing later in the run. 2. Confirm the signals are hitting the right workflow instanceSince you’re using Livewire buttons to call the signal methods, under the hood you’re doing something like: $workflow = WorkflowStub::load($workflowId);
$workflow->setApproval2(true);
$workflow->setApproval3(true);Things to double-check:
If signals go to the wrong workflow, fn () => $this->approval2 && $this->approval3never becomes This doesn’t depend on parallel vs sequential, but parallel often makes these timing issues more visible. 3. Verify the
|
Beta Was this translation helpful? Give feedback.
UPDATE: @chipotlegroove I have fixed this issue. I have also added your exact scenario as a test case to make sure it won't break again in the future. I have released 1.0.43 with the fix. I have also tested the fix with that previous livewire I reproduced your issue with and I confirmed that it is now fixed. If you still have issues feel free to open an issue. Thanks for your patience and your help with fixing this issue!