Struggling to create a simple logical approach to handling a workflow with a loop scenario #85
tonypartridge
started this conversation in
General
Replies: 2 comments
-
public function execute($userId, $details)
{
// Email Crewing Manager to review details
$this->details = $details;
$sentInitiationMail = yield ActivityStub::make(InitiateApproval::class, $details);
// Wait for a signal from the Crewing Manager to decide where we go next, this could loop a few times!
do {
// if review was rejected then notify client and wait for updated details
if ($this->reviewStatus === 'REJECTED') {
yield ActivityStub::make(InitiateRejected::class, $details->form['crewing_approval_rejected_details']);
} else {
// if review was approved then send details to Athena
yield ActivityStub::make(InitiateApproval::class, $details);
}
// wait for an update again....
yield WorkflowStub::await(fn () => $this->updated);
} while ($this->reviewStatus !== 'APPROVED');
// Now it's approved, send the details to Athena
return true;
}Is what I have tried, but it enters a never ending loop of sending emails for InitiateApproval. |
Beta Was this translation helpful? Give feedback.
0 replies
-
<?php
declare(strict_types=1);
namespace App\Workflows\Loop;
use Workflow\ActivityStub;
use Workflow\SignalMethod;
use Workflow\Workflow;
use Workflow\WorkflowStub;
class LoopWorkflow extends Workflow
{
private $reviewStatus = '';
#[SignalMethod]
public function setReviewStatus($reviewStatus)
{
$this->reviewStatus = $reviewStatus;
}
public function execute($userId, $details)
{
do {
yield ActivityStub::make(InitiateApproval::class, $details);
yield WorkflowStub::await(fn () => $this->reviewStatus !== '');
if ($this->reviewStatus === 'REJECTED') {
yield ActivityStub::make(InitiateRejected::class, $details);
return false;
}
} while ($this->reviewStatus !== 'APPROVED');
return true;
}
}<?php
declare(strict_types=1);
namespace App\Workflows\Loop;
use Workflow\Activity;
class InitiateApproval extends Activity
{
public function execute($details)
{
// send email
}
}<?php
declare(strict_types=1);
namespace App\Workflows\Loop;
use Workflow\Activity;
class InitiateRejected extends Activity
{
public function execute($details)
{
// send email
}
}$workflow = WorkflowStub::make(LoopWorkflow::class);
$workflow->start(1, []);
sleep(5);
$workflow->setReviewStatus('REJECTED');
while ($workflow->running());
$this->info($workflow->output()); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a use case right now thats fairly simple:
Form is filled out and sent for review
Reviewer receives email and reviews, if declined it triggers another email with the reason from the form and sends it to the initiator for review, they review, update and then it triggers back to reviewer and loops until they reviewer approves it.
Once Approved, send email to email within the form with details.
Email in form with the details, reviews and accepts or declines, if declines it provides a reason. workflow then emails initiator and review with the reason and notice.
If accepted, another email goes out to add more details when they are ready.
Once details added, email goes to reviewer/initiator with the submitted details
End off.
What I can't get my head around right now is the simple condition to await for the right reason between the two workflow states.
Beta Was this translation helpful? Give feedback.
All reactions