Skip to content

Commit 5194355

Browse files
authored
Document updates and outbox features in workflows
Added documentation for updates and outbox features in workflows, including examples of defining update methods and using the outbox to manage outgoing messages.
1 parent 7236698 commit 5194355

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

docs/features/queries.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,59 @@ $ready = $workflow->getReady();
3939
<QuerySimulator />
4040

4141
**Important:** Querying a workflow does not advance its execution, unlike signals.
42+
43+
# Updates
44+
45+
Updates allow you to retrieve information about the current state of a workflow and mutate the workflow state at the same time. They are essentially both a query and a signal combined into one.
46+
47+
To define an update method on a workflow, use the `UpdateMethod` annotation:
48+
49+
```php
50+
use Workflow\UpdateMethod;
51+
use Workflow\Workflow;
52+
53+
class MyWorkflow extends Workflow
54+
{
55+
private bool $ready = false;
56+
57+
#[UpdateMethod]
58+
public function updateReady($ready): bool
59+
{
60+
$this->ready = $ready;
61+
62+
return $this->ready;
63+
}
64+
}
65+
```
66+
67+
## Outbox
68+
69+
The outbox collects outgoing query messages and lets you produce them exactly once, even if the workflow is replayed or resumed multiple times.
70+
71+
```php
72+
use Workflow\UpdateMethod;
73+
use Workflow\Workflow;
74+
75+
class MyWorkflow extends Workflow
76+
{
77+
#[UpdateMethod]
78+
public function receive()
79+
{
80+
if ($this->outbox->hasUnsent()) {
81+
return $this->outbox->nextUnsent();
82+
}
83+
}
84+
85+
public function execute()
86+
{
87+
$count = 0;
88+
while (true) {
89+
$count++;
90+
91+
$this->outbox->send("Message {$count");
92+
}
93+
}
94+
}
95+
```
96+
97+
Each sent signal is stored in the outbox. The outbox tracks which messages have already been sent. On replay, previously read messages remain sent. Only unsent messages are returned by `nextUnsent()`. This makes the outbox safe to send multiple messages inside long-running loops.

0 commit comments

Comments
 (0)