-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrchestrationContextInterface.php
More file actions
233 lines (200 loc) · 6.88 KB
/
OrchestrationContextInterface.php
File metadata and controls
233 lines (200 loc) · 6.88 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/*
* Copyright ©2024 Robert Landers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Bottledcode\DurablePhp;
use Bottledcode\DurablePhp\State\EntityId;
use Bottledcode\DurablePhp\State\EntityLock;
use Bottledcode\DurablePhp\State\OrchestrationInstance;
use Closure;
use DateInterval;
use DateTimeImmutable;
use Psr\Log\LoggerInterface;
use Ramsey\Uuid\UuidInterface;
interface OrchestrationContextInterface
{
/**
* Call an activity function and return a future that the context can await on.
*
* @template T
*
* @param string $name The name of the function to remotely invoke
* @param class-string<T>|null $returnType
* @param RetryOptions|null $retryOptions How to retry on failure
* @param array $args The arguments to pass to the function
* @return DurableFuture<T>
*/
public function callActivity(string $name, ?string $returnType = null, ?RetryOptions $retryOptions = null, mixed ...$args): DurableFuture;
/**
* Calls an activity inline. There are no retries and exceptions will cause an immediate failure.
*/
public function callActivityInline(Closure $activity): DurableFuture;
/**
* Call an entity and get the response
*
* @template T
*
* @return DurableFuture<T>
*/
public function callEntity(EntityId $entityId, string $operation, array $args = []): DurableFuture;
/**
* Get a logger that only logs when not replaying
*/
public function getReplayAwareLogger(): LoggerInterface;
public function signalEntity(EntityId $entityId, string $operation, array $args = []): void;
/**
* @template T
* @template V
*
* @param Closure(T): V $operation
* @return V
*/
public function entityOp(EntityId|string $id, Closure $operation): mixed;
/**
* Determines if an entity is locked. Returns true if the entity is locked.
*/
public function isLocked(EntityId $entityId): bool;
/**
* Determines if the current lock is owned by the current instance.
*/
public function isLockedOwned(EntityId $entityId): bool;
/**
* Attempts to lock an entity. Returns once the lock is acquired.
*/
public function lockEntity(EntityId ...$entityId): EntityLock;
public function callSubOrchestrator(
string $name,
?string $instanceId = null,
?RetryOptions $retryOptions = null,
mixed ...$args,
): DurableFuture;
public function continueAsNew(array $args = []): never;
/**
* Creates a durable timer that resolves at the specified time.
*
* @param DateTimeImmutable $fireAt The time to resolve the future.
* @return DurableFuture<true>
*/
public function createTimer(DateTimeImmutable $fireAt): DurableFuture;
/**
* The input to the orchestrator function.
*
* @return array<array-key, mixed>
*/
public function getInput(): array;
/**
* Constructs a db-friendly GUID.
*/
public function newGuid(): UuidInterface;
/**
* Set the custom status of the orchestration.
*
* @param string $customStatus The new status.
*/
public function setCustomStatus(string $customStatus): void;
/**
* Waits for an external event to be raised. May resolve immediately if the event has already been raised.
*
* @template T
*
* @param class-string<T>|null $resultType
* @return DurableFuture<T>
*/
public function waitForExternalEvent(string $name, ?string $resultType = null): DurableFuture;
/**
* Gets the current time in a deterministic way. (always the time the execution started)
*/
public function getCurrentTime(): DateTimeImmutable;
/**
* Retrieve the current custom status or null if none has been set.
*/
public function getCustomStatus(): ?string;
/**
* Retrieve the current orchestration instance id.
*/
public function getCurrentId(): OrchestrationInstance;
/**
* Whether we're replaying an orchestration on this particular line of code.
*
* Warning: do not use this for i/o or other side effects.
*/
public function isReplaying(): bool;
/**
* Retrieve a parent orchestration if there is one.
*/
public function getParentId(): ?OrchestrationInstance;
/**
* Whether the orchestration will restart as a new orchestration.
*/
public function willContinueAsNew(): bool;
/**
* A helper method for creating a DateInterval.
*/
public function createInterval(
?int $years = null,
?int $months = null,
?int $weeks = null,
?int $days = null,
?int $hours = null,
?int $minutes = null,
?int $seconds = null,
?int $microseconds = null,
): DateInterval;
/**
* Returns the first successful future to complete.
*/
public function waitAny(DurableFuture ...$tasks): DurableFuture;
/**
* Returns once all futures have completed.
*
* @template-covariant T
*
* @return array<T>
*/
public function waitAll(DurableFuture ...$tasks): array;
/**
* Returns the result (or throws on failure) once a single future has completed.
*
* @template T
*
* @param DurableFuture<T> $task
* @return T
*/
public function waitOne(DurableFuture $task): mixed;
/**
* Creates a simple proxy for the given class
*
* @template T
*
* @param class-string<T> $className
* @return T
*/
public function createEntityProxy(string $className, ?EntityId $entityId = null): object;
/**
* Cryptographic random ints
*/
public function getRandomInt(int $min, int $max): int;
/**
* Cryptographic random bytes
*/
public function getRandomBytes(int $length): string;
public function getCurrentUserId(): string;
}