FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cli/src/Support/ExternalTaskResultContract.php at main · durable-workflow/cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
durable-workflow
/
cli
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cli
/
src
/
Support
/
ExternalTaskResultContract.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
306 lines (251 loc) · 10.4 KB
Breadcrumbs
cli
/
src
/
Support
/
ExternalTaskResultContract.php
Copy path
File metadata and controls
306 lines (251 loc) · 10.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
declare
(strict_types=
1
);
namespace
DurableWorkflow
\
Cli
\
Support
;
final
class
ExternalTaskResultContract
{
public
const
SCHEMA
=
'
durable-workflow.v2.external-task-result.contract
'
;
public
const
VERSION
=
1
;
public
const
ENVELOPE_SCHEMA
=
'
durable-workflow.v2.external-task-result
'
;
public
const
MEDIA_TYPE
=
'
application/vnd.durable-workflow.external-task-result+json
'
;
private
const
REQUIRED_FIXTURES
= [
'
success
'
=>
'
durable-workflow.v2.external-task-result.success.v1
'
,
'
failure
'
=>
'
durable-workflow.v2.external-task-result.failure.v1
'
,
'
malformed_output
'
=>
'
durable-workflow.v2.external-task-result.malformed-output.v1
'
,
'
cancellation
'
=>
'
durable-workflow.v2.external-task-result.cancellation.v1
'
,
'
handler_crash
'
=>
'
durable-workflow.v2.external-task-result.handler-crash.v1
'
,
'
decode_failure
'
=>
'
durable-workflow.v2.external-task-result.decode-failure.v1
'
,
'
unsupported_payload_codec
'
=>
'
durable-workflow.v2.external-task-result.unsupported-payload-codec.v1
'
,
'
unsupported_payload_reference
'
=>
'
durable-workflow.v2.external-task-result.unsupported-payload-reference.v1
'
,
];
/**
* @return list<string>
*/
public
static
function
fixtureNames
():
array
{
return
array_keys
(
self
::
REQUIRED_FIXTURES
);
}
public
static
function
expected
():
string
{
return
sprintf
(
'
%s v%d
'
,
self
::
SCHEMA
,
self
::
VERSION
);
}
/**
* @param array<string, mixed> $clusterInfo
*/
public
static
function
warning
(
array
$
clusterInfo
): ?
string
{
if
(!
self
::
serverRequiresContract
(
$
clusterInfo
) && !
self
::
hasPublishedManifest
(
$
clusterInfo
)) {
return
null
;
}
$
workerProtocol
=
$
clusterInfo
[
'
worker_protocol
'
] ??
null
;
$
manifest
=
is_array
(
$
workerProtocol
) ?
$
workerProtocol
[
'
external_task_result_contract
'
] ??
null
:
null
;
if
(!
is_array
(
$
manifest
)) {
return
sprintf
(
'
Compatibility warning: server did not advertise worker_protocol.external_task_result_contract; dw CLI expects %s.
'
,
self
::
expected
(),
);
}
$
schema
=
$
manifest
[
'
schema
'
] ??
null
;
$
version
=
$
manifest
[
'
version
'
] ??
null
;
if
(
$
schema
!==
self
::
SCHEMA
|| !
self
::
versionMatches
(
$
version
)) {
return
sprintf
(
'
Compatibility warning: server advertises worker_protocol.external_task_result_contract [%s v%s]; dw CLI expects %s.
'
,
is_scalar
(
$
schema
) ? (
string
)
$
schema
:
'
missing
'
,
is_scalar
(
$
version
) ? (
string
)
$
version
:
'
missing
'
,
self
::
expected
(),
);
}
$
errors
=
self
::
validateManifest
(
$
manifest
);
if
(
$
errors
!== []) {
return
sprintf
(
'
Compatibility warning: server worker_protocol.external_task_result_contract is missing consumable fixture artifact coverage: %s.
'
,
$
errors
[
0
],
);
}
return
null
;
}
/**
* @param array<string, mixed> $clusterInfo
* @return array<string, mixed>|null
*/
public
static
function
diagnostic
(
array
$
clusterInfo
): ?
array
{
$
workerProtocol
=
$
clusterInfo
[
'
worker_protocol
'
] ??
null
;
$
manifest
=
is_array
(
$
workerProtocol
) ?
$
workerProtocol
[
'
external_task_result_contract
'
] ??
null
:
null
;
if
(!
is_array
(
$
manifest
)) {
return
null
;
}
$
fixtures
=
is_array
(
$
manifest
[
'
fixtures
'
] ??
null
) ?
$
manifest
[
'
fixtures
'
] : [];
return
[
'
schema
'
=>
is_scalar
(
$
manifest
[
'
schema
'
] ??
null
) ? (
string
)
$
manifest
[
'
schema
'
] :
null
,
'
version
'
=>
is_scalar
(
$
manifest
[
'
version
'
] ??
null
) ? (
int
)
$
manifest
[
'
version
'
] :
null
,
'
fixtures
'
=>
array_values
(
array_intersect
(
array_keys
(
$
fixtures
),
self
::
fixtureNames
())),
'
valid
'
=>
self
::
validateManifest
(
$
manifest
) === [],
];
}
/**
* @param array<string, mixed> $manifest
* @return list<string>
*/
public
static
function
validateManifest
(
array
$
manifest
):
array
{
$
errors
= [];
$
fixtures
=
$
manifest
[
'
fixtures
'
] ??
null
;
if
(!
is_array
(
$
fixtures
)) {
return
[
'
fixtures must be an object keyed by artifact role
'
];
}
foreach
(
self
::
REQUIRED_FIXTURES
as
$
name
=>
$
artifactName
) {
$
artifact
=
$
fixtures
[
$
name
] ??
null
;
if
(!
is_array
(
$
artifact
)) {
$
errors
[] =
sprintf
(
'
missing fixture [%s]
'
,
$
name
);
continue
;
}
$
errors
=
array_merge
(
$
errors
,
self
::
validateArtifact
(
$
name
,
$
artifactName
,
$
artifact
));
}
return
$
errors
;
}
/**
* @param array<string, mixed> $clusterInfo
*/
private
static
function
hasPublishedManifest
(
array
$
clusterInfo
):
bool
{
$
workerProtocol
=
$
clusterInfo
[
'
worker_protocol
'
] ??
null
;
return
is_array
(
$
workerProtocol
) &&
array_key_exists
(
'
external_task_result_contract
'
,
$
workerProtocol
);
}
/**
* @param array<string, mixed> $clusterInfo
*/
private
static
function
serverRequiresContract
(
array
$
clusterInfo
):
bool
{
$
compatibility
=
$
clusterInfo
[
'
client_compatibility
'
] ??
null
;
if
(!
is_array
(
$
compatibility
)) {
return
false
;
}
$
requiredProtocols
=
$
compatibility
[
'
required_protocols
'
] ??
null
;
if
(
is_array
(
$
requiredProtocols
)) {
$
workerProtocol
=
$
requiredProtocols
[
'
worker_protocol
'
] ??
null
;
if
(
is_array
(
$
workerProtocol
) &&
array_key_exists
(
'
external_task_result_contract
'
,
$
workerProtocol
)) {
return
true
;
}
}
$
clients
=
$
compatibility
[
'
clients
'
] ??
null
;
$
cli
=
is_array
(
$
clients
) ?
$
clients
[
'
cli
'
] ??
null
:
null
;
$
requires
=
is_array
(
$
cli
) ?
$
cli
[
'
requires
'
] ??
null
:
null
;
if
(!
is_array
(
$
requires
)) {
return
false
;
}
foreach
(
$
requires
as
$
requirement
) {
if
(
is_string
(
$
requirement
) &&
str_starts_with
(
$
requirement
,
'
worker_protocol.external_task_result_contract
'
)) {
return
true
;
}
}
return
false
;
}
private
static
function
versionMatches
(
mixed
$
version
):
bool
{
return
is_int
(
$
version
) || (
is_string
(
$
version
) &&
ctype_digit
(
$
version
))
? (
int
)
$
version
===
self
::
VERSION
:
false
;
}
/**
* @param array<string, mixed> $artifact
* @return list<string>
*/
private
static
function
validateArtifact
(
string
$
name
,
string
$
artifactName
,
array
$
artifact
):
array
{
$
errors
= [];
if
((
$
artifact
[
'
artifact
'
] ??
null
) !==
$
artifactName
) {
$
errors
[] =
sprintf
(
'
fixture [%s] has artifact [%s]
'
,
$
name
,
self
::
display
(
$
artifact
[
'
artifact
'
] ??
null
));
}
if
((
$
artifact
[
'
media_type
'
] ??
null
) !==
self
::
MEDIA_TYPE
) {
$
errors
[] =
sprintf
(
'
fixture [%s] has media type [%s]
'
,
$
name
,
self
::
display
(
$
artifact
[
'
media_type
'
] ??
null
));
}
if
((
$
artifact
[
'
schema
'
] ??
null
) !==
self
::
ENVELOPE_SCHEMA
|| !
self
::
versionMatches
(
$
artifact
[
'
version
'
] ??
null
)) {
$
errors
[] =
sprintf
(
'
fixture [%s] has unsupported envelope schema/version
'
,
$
name
);
}
$
example
=
$
artifact
[
'
example
'
] ??
null
;
if
(!
is_array
(
$
example
)) {
$
errors
[] =
sprintf
(
'
fixture [%s] is missing an embedded example
'
,
$
name
);
return
$
errors
;
}
$
sha
=
hash
(
'
sha256
'
, (
string
)
json_encode
(
$
example
,
JSON_UNESCAPED_SLASHES
));
if
((
$
artifact
[
'
sha256
'
] ??
null
) !==
$
sha
) {
$
errors
[] =
sprintf
(
'
fixture [%s] sha256 does not match embedded example
'
,
$
name
);
}
return
array_merge
(
$
errors
,
self
::
validateExample
(
$
name
,
$
example
));
}
/**
* @param array<string, mixed> $example
* @return list<string>
*/
private
static
function
validateExample
(
string
$
name
,
array
$
example
):
array
{
$
errors
= [];
if
((
$
example
[
'
schema
'
] ??
null
) !==
self
::
ENVELOPE_SCHEMA
|| !
self
::
versionMatches
(
$
example
[
'
version
'
] ??
null
)) {
$
errors
[] =
sprintf
(
'
fixture [%s] example has unsupported envelope schema/version
'
,
$
name
);
}
$
outcome
=
$
example
[
'
outcome
'
] ??
null
;
if
(!
is_array
(
$
outcome
)) {
$
errors
[] =
sprintf
(
'
fixture [%s] example is missing outcome object
'
,
$
name
);
return
$
errors
;
}
$
status
=
$
outcome
[
'
status
'
] ??
null
;
if
(
$
name
===
'
success
'
) {
if
(
$
status
!==
'
succeeded
'
|| !
array_key_exists
(
'
result
'
,
$
example
)) {
$
errors
[] =
'
fixture [success] must be a succeeded envelope with result
'
;
}
return
$
errors
;
}
if
(
$
status
!==
'
failed
'
|| !
is_array
(
$
example
[
'
failure
'
] ??
null
)) {
$
errors
[] =
sprintf
(
'
fixture [%s] must be a failed envelope with failure object
'
,
$
name
);
return
$
errors
;
}
$
failure
=
$
example
[
'
failure
'
];
if
(!
in_array
(
$
failure
[
'
kind
'
] ??
null
,
self
::
failureKinds
(),
true
)) {
$
errors
[] =
sprintf
(
'
fixture [%s] has unsupported failure kind [%s]
'
,
$
name
,
self
::
display
(
$
failure
[
'
kind
'
] ??
null
));
}
if
(!
in_array
(
$
failure
[
'
classification
'
] ??
null
,
self
::
failureClassifications
(),
true
)) {
$
errors
[] =
sprintf
(
'
fixture [%s] has unsupported failure classification [%s]
'
,
$
name
,
self
::
display
(
$
failure
[
'
classification
'
] ??
null
),
);
}
return
$
errors
;
}
/**
* @return list<string>
*/
private
static
function
failureKinds
():
array
{
return
[
'
application
'
,
'
timeout
'
,
'
cancellation
'
,
'
malformed_output
'
,
'
handler_crash
'
,
'
decode_failure
'
,
'
unsupported_payload
'
,
];
}
/**
* @return list<string>
*/
private
static
function
failureClassifications
():
array
{
return
[
'
application_error
'
,
'
timeout
'
,
'
cancelled
'
,
'
deadline_exceeded
'
,
'
handler_crash
'
,
'
decode_failure
'
,
'
malformed_output
'
,
'
unsupported_payload_codec
'
,
'
unsupported_payload_reference
'
,
];
}
private
static
function
display
(
mixed
$
value
):
string
{
return
is_scalar
(
$
value
) ? (
string
)
$
value
:
'
missing
'
;
}
}
Back
|
FazBrowse Home
|
New Git URL