-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathGeneratorWorkflow.php
More file actions
62 lines (52 loc) · 1.57 KB
/
GeneratorWorkflow.php
File metadata and controls
62 lines (52 loc) · 1.57 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Temporal\Tests\Workflow;
use Temporal\Activity\ActivityOptions;
use Temporal\Common\RetryOptions;
use Temporal\Internal\Workflow\ActivityProxy;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;
#[Workflow\WorkflowInterface]
class GeneratorWorkflow
{
#[WorkflowMethod(name: 'GeneratorWorkflow')]
public function handler(
string $input
) {
// typed stub
$simple = Workflow::newActivityStub(
SimpleActivity::class,
ActivityOptions::new()->withStartToCloseTimeout(5)->withRetryOptions(
RetryOptions::new()->withMaximumAttempts(1)
)
);
return [
yield $this->doSomething($simple, $input),
yield $this->doSomething($simple, 'another')
];
}
/**
* @param ActivityProxy<SimpleActivity> $simple
*/
private function doSomething(ActivityProxy $simple, string $input): \Generator
{
if ($input === 'error') {
throw new \Exception('error from generator');
}
if ($input === 'failure') {
yield $simple->fail();
throw new \Exception('Unreachable statement');
}
$result = [];
$result[] = yield $simple->echo($input);
$result[] = yield $simple->echo($input);
return $result;
}
}