Skip to main content

Side Effects

A side effect is a closure containing non-deterministic code. The closure is only executed once and the result is saved. It will not execute again if the workflow is retried. Instead, it will return the saved result.

use Workflow\Workflow;
use Workflow\WorkflowStub;

class MyWorkflow extends Workflow
{
public function execute()
{
$seconds = yield WorkflowStub::sideEffect(fn () => random_int(60, 120));

yield WorkflowStub::timer($seconds);
}
}

The workflow will only call random_int() once and save the result, even if the workflow later fails and is retried.

Important: The code inside a side effect should never fail because it will not be retried. Code that can possibly fail and therefore need to be retried should be moved to an activity instead.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy