Skip to content

Commit ae94a39

Browse files
authored
Update timers documentation for workflow time handling
Clarify usage of time functions in workflows and update code examples.
1 parent 22bce26 commit ae94a39

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docs/features/timers.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ class MyWorkflow extends Workflow
2929

3030
You may also specify the time to wait as a string e.g. '5 seconds', '30 minutes' or even '3 days'. Laravel Workflow can handle any duration.
3131

32-
**Important:** When using timers, do not use `Carbon::now()` to get the current time. Instead, use `WorkflowStub::now()`, which returns the current time as seen by the workflow system. This is crucial because the actual time may not match your application's system clock.
32+
**Important:** Inside of a workflow, never use `Carbon::now()` or Laravel's `now()` to get the current time. Instead, use `Workflow\now()`, which returns the current time as seen by the workflow system. This is crucial because the actual time may not match your application's system clock.
33+
34+
```php
35+
use function Workflow\now;
36+
```
3337

3438
Additionally, when measuring elapsed time in workflows (e.g., tracking how long an activity takes), always get your start and end times with:
3539

3640
```php
37-
use function Workflow\sideEffect;
41+
use function Workflow\{now, sideEffect};
3842

39-
$start = yield sideEffect(fn () => WorkflowStub::now());
43+
$start = yield sideEffect(fn () => now());
4044
```
4145

4246
This ensures an event log is created, preventing replay-related inconsistencies and guaranteeing accurate time calculations.

0 commit comments

Comments
 (0)