Skip to content

Call an activity in a loop? #139

Closed Answered by rmcdaniel
feuzeu asked this question in Q&A
Oct 16, 2023 · 7 comments · 3 replies
Discussion options

You must be logged in to vote

If you invoke ActivityStub::make() multiple times within a loop, it doesn't just return the same result as the first call. Instead, it will initiate and execute the activity for each call.

For example:

for ($i=0; $i < 2; $i++) {
    yield ActivityStub::make(SimpleActivity::class);
}

This is equivalent to:

yield ActivityStub::make(SimpleActivity::class);
yield ActivityStub::make(SimpleActivity::class);

In both instances, the activity will be executed twice. It's only when a workflow crashes and is reloaded that the same result might be fetched from the logs to avoid redundant operations. So, your activity will indeed run each time you call it in your loop.

Replies: 7 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by feuzeu
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@feuzeu
Comment options

Comment options

You must be logged in to vote
2 replies
@feuzeu
Comment options

@rmcdaniel
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants