-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.php
More file actions
68 lines (56 loc) · 1.82 KB
/
Copy pathworker.php
File metadata and controls
68 lines (56 loc) · 1.82 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
63
64
65
66
67
68
<?php
declare(strict_types=1);
require dirname(__DIR__).'/vendor/autoload.php';
use DurableWorkflow\Attribute\Activity;
use DurableWorkflow\Attribute\Query;
use DurableWorkflow\Attribute\Signal;
use DurableWorkflow\Attribute\Update;
use DurableWorkflow\Attribute\Workflow;
use DurableWorkflow\Client;
use DurableWorkflow\Worker;
use DurableWorkflow\Worker\ActivityContext;
use DurableWorkflow\Worker\QueryContext;
use DurableWorkflow\Worker\WorkflowContext;
final class GreeterWorkflow
{
#[Workflow('greeter')]
public function run(WorkflowContext $context, string $name): Generator
{
$greeting = yield $context->activity('greet', [$name], [
'start_to_close_timeout' => 30,
'heartbeat_timeout' => 10,
]);
return ['greeting' => $greeting];
}
#[Query]
public function status(QueryContext $context): array
{
return ['events' => count($context->history), 'run_id' => $context->runId];
}
#[Signal('set-language')]
public function setLanguage(string $language): void
{
// The signature declares admission; run() consumes context signals during replay.
}
#[Update]
public function rename(QueryContext $context, string $name): array
{
return ['accepted_name' => $name, 'run_id' => $context->runId];
}
}
final class GreetingActivities
{
#[Activity('greet')]
public function greet(ActivityContext $context, string $name): string
{
$context->heartbeat(['phase' => 'formatting']);
return "hello, {$name}";
}
}
$client = new Client(
getenv('DURABLE_WORKFLOW_SERVER_URL') ?: 'http://localhost:8080',
token: getenv('DURABLE_WORKFLOW_AUTH_TOKEN') ?: 'dev-token-123',
);
Worker::create($client, 'php-workers')
->register(GreeterWorkflow::class, GreetingActivities::class)
->run();