Retry failed activity #241
-
|
Hi! Wondering if it's a missing feature or against any philosophy of the package but I would like to be able to retry workflows with failed activities (limited number of job tries). Why Issue Or am I looking at this all wrong? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
This is where it is important to make the distinction between workflow status and business status.
Exampleclass MyWorkflow extends Workflow
{
private bool $readyToRetry = false;
#[SignalMethod]
public function retry()
{
$this->readyToRetry = true;
}
public function execute()
{
while (true) {
try {
yield ActivityStub::make(MyRiskyActivity::class);
break; // Success, exit loop
} catch (\Throwable $e) {
// Pause until signal is received
yield WorkflowStub::await(fn () => $this->readyToRetry);
$this->readyToRetry = false; // reset flag for future retries
}
}
}
}What This Does
|
Beta Was this translation helpful? Give feedback.
-
|
For anyone ending up here, and potential bug report to you @rmcdaniel, for this to work it seems that we have to yield a resolve before we move on to the await, otherwise it get stuck. See working code below while (true) {
try {
yield ActivityStub::make($activity, ...$arguments);
break; // Success, exit loop
} catch (Throwable $e) {
// This yield is a quickfix for the while loop in WorkflowVendor
// Otherwise it will get stuck on the first promise from the await
// since the signals are sent after the "first" promise is resolved
yield resolve('Has thrown exception');
// Pause until signal is received
yield WorkflowStub::await(fn () => $this->readyToRetry);
// reset flag for future retries
$this->readyToRetry = false;
}
}Since the throwing yield doesn't return anything and we haven't yet read the signals in the first step, we don't solve that promise and it returns on this part in if (! $resolved) {
if (! $this->replaying) {
$this->storedWorkflow->status->transitionTo(WorkflowWaitingStatus::class);
}
return;
}We however need it to not return, loop another time and read the signal that has been sent so that it may continue after the await. |
Beta Was this translation helpful? Give feedback.
This is where it is important to make the distinction between workflow status and business status.
Example