blob: b11d786459722dcff1146c3e47e0334907c3f9bb (
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
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
69
70
71
72
73
74
75
76
77
|
# About Temporal.IO
Temporal is a distributed, scalable, durable, and highly available orchestration engine used to execute asynchronous
long-running business logic in a scalable and resilient way.
Read more at [official website](https://docs.temporal.io/docs/overview/).
RoadRunner 2.0 includes a plugin to execute Temporal workflows and activities. Make sure to write [temporal worker](/workflow/worker.md).
Activate plugin via config:
```yaml
rpc:
listen: tcp://127.0.0.1:6001
server:
command: "php worker.php"
temporal:
address: "localhost:7233"
activities:
num_workers: 10
logs:
level: debug
channels:
temporal.level: error
```
## Example
Integrated workflow server provides the ability to create very complex, long-running activities.
```php
class SubscriptionWorkflow implements SubscriptionWorkflowInterface
{
private $account;
public function __construct()
{
$this->account = Workflow::newActivityStub(
AccountActivityInterface::class,
ActivityOptions::new()
->withScheduleToCloseTimeout(DateInterval::createFromDateString('2 seconds'))
);
}
public function subscribe(string $userID)
{
yield $this->account->sendWelcomeEmail($userID);
try {
$trialPeriod = true;
while (true) {
// Lower period duration to observe workflow behavior
yield Workflow::timer(DateInterval::createFromDateString('30 days'));
yield $this->account->chargeMonthlyFee($userID);
if ($trialPeriod) {
yield $this->account->sendEndOfTrialEmail($userID);
$trialPeriod = false;
continue;
}
yield $this->account->sendMonthlyChargeEmail($userID);
}
} catch (CanceledFailure $e) {
yield Workflow::asyncDetached(
function () use ($userID) {
yield $this->account->processSubscriptionCancellation($userID);
yield $this->account->sendSorryToSeeYouGoEmail($userID);
}
);
}
}
}
```
> Read more at [official website](https://docs.temporal.io/docs/php-sdk-overview).
|