summaryrefslogtreecommitdiff
path: root/tests/temporal/Workflow/ContinuableWorkflow.php
blob: 78411414f3fafd0ad990407cef98dda0e4dd7b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php


namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityOptions;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;
use Temporal\Tests\Activity\SimpleActivity;

#[Workflow\WorkflowInterface]
class ContinuableWorkflow
{
    #[WorkflowMethod(name: 'ContinuableWorkflow')]
    public function handler(
        int $generation
    ) {
        $simple = Workflow::newActivityStub(
            SimpleActivity::class,
            ActivityOptions::new()->withStartToCloseTimeout(5)
        );

        if ($generation > 5) {
            // complete
            return "OK" . $generation;
        }

        if ($generation !== 1) {
            assert(!empty(Workflow::getInfo()->continuedExecutionRunId));
        }

        for ($i = 0; $i < $generation; $i++) {
            yield $simple->echo((string)$generation);
        }

        return Workflow::continueAsNew('ContinuableWorkflow', [++$generation]);
    }
}