azure-functions-durable 1.2.9__py3-none-any.whl → 1.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- azure/durable_functions/__init__.py +81 -81
- azure/durable_functions/constants.py +9 -9
- azure/durable_functions/decorators/__init__.py +3 -3
- azure/durable_functions/decorators/durable_app.py +260 -249
- azure/durable_functions/decorators/metadata.py +109 -109
- azure/durable_functions/entity.py +129 -125
- azure/durable_functions/models/DurableEntityContext.py +201 -201
- azure/durable_functions/models/DurableHttpRequest.py +58 -58
- azure/durable_functions/models/DurableOrchestrationBindings.py +66 -66
- azure/durable_functions/models/DurableOrchestrationClient.py +812 -781
- azure/durable_functions/models/DurableOrchestrationContext.py +761 -707
- azure/durable_functions/models/DurableOrchestrationStatus.py +156 -156
- azure/durable_functions/models/EntityStateResponse.py +23 -23
- azure/durable_functions/models/FunctionContext.py +7 -7
- azure/durable_functions/models/OrchestrationRuntimeStatus.py +32 -32
- azure/durable_functions/models/OrchestratorState.py +117 -116
- azure/durable_functions/models/PurgeHistoryResult.py +33 -33
- azure/durable_functions/models/ReplaySchema.py +9 -8
- azure/durable_functions/models/RetryOptions.py +69 -69
- azure/durable_functions/models/RpcManagementOptions.py +86 -86
- azure/durable_functions/models/Task.py +540 -426
- azure/durable_functions/models/TaskOrchestrationExecutor.py +352 -336
- azure/durable_functions/models/TokenSource.py +56 -56
- azure/durable_functions/models/__init__.py +26 -24
- azure/durable_functions/models/actions/Action.py +23 -23
- azure/durable_functions/models/actions/ActionType.py +18 -18
- azure/durable_functions/models/actions/CallActivityAction.py +41 -41
- azure/durable_functions/models/actions/CallActivityWithRetryAction.py +45 -45
- azure/durable_functions/models/actions/CallEntityAction.py +46 -46
- azure/durable_functions/models/actions/CallHttpAction.py +35 -35
- azure/durable_functions/models/actions/CallSubOrchestratorAction.py +40 -40
- azure/durable_functions/models/actions/CallSubOrchestratorWithRetryAction.py +44 -44
- azure/durable_functions/models/actions/CompoundAction.py +35 -35
- azure/durable_functions/models/actions/ContinueAsNewAction.py +36 -36
- azure/durable_functions/models/actions/CreateTimerAction.py +48 -48
- azure/durable_functions/models/actions/NoOpAction.py +35 -35
- azure/durable_functions/models/actions/SignalEntityAction.py +47 -47
- azure/durable_functions/models/actions/WaitForExternalEventAction.py +63 -63
- azure/durable_functions/models/actions/WhenAllAction.py +14 -14
- azure/durable_functions/models/actions/WhenAnyAction.py +14 -14
- azure/durable_functions/models/actions/__init__.py +24 -24
- azure/durable_functions/models/entities/EntityState.py +74 -74
- azure/durable_functions/models/entities/OperationResult.py +94 -76
- azure/durable_functions/models/entities/RequestMessage.py +53 -53
- azure/durable_functions/models/entities/ResponseMessage.py +48 -48
- azure/durable_functions/models/entities/Signal.py +62 -62
- azure/durable_functions/models/entities/__init__.py +17 -17
- azure/durable_functions/models/history/HistoryEvent.py +92 -92
- azure/durable_functions/models/history/HistoryEventType.py +27 -27
- azure/durable_functions/models/history/__init__.py +8 -8
- azure/durable_functions/models/utils/__init__.py +7 -7
- azure/durable_functions/models/utils/entity_utils.py +103 -91
- azure/durable_functions/models/utils/http_utils.py +80 -69
- azure/durable_functions/models/utils/json_utils.py +96 -56
- azure/durable_functions/orchestrator.py +73 -71
- azure/durable_functions/testing/OrchestratorGeneratorWrapper.py +42 -0
- azure/durable_functions/testing/__init__.py +6 -0
- {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.3.0.dist-info}/LICENSE +21 -21
- {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.3.0.dist-info}/METADATA +59 -58
- azure_functions_durable-1.3.0.dist-info/RECORD +103 -0
- {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.3.0.dist-info}/WHEEL +1 -1
- tests/models/test_DecoratorMetadata.py +135 -135
- tests/models/test_Decorators.py +107 -107
- tests/models/test_DurableOrchestrationBindings.py +68 -68
- tests/models/test_DurableOrchestrationClient.py +730 -730
- tests/models/test_DurableOrchestrationContext.py +102 -102
- tests/models/test_DurableOrchestrationStatus.py +59 -59
- tests/models/test_OrchestrationState.py +28 -28
- tests/models/test_RpcManagementOptions.py +79 -79
- tests/models/test_TokenSource.py +10 -10
- tests/orchestrator/models/OrchestrationInstance.py +18 -18
- tests/orchestrator/orchestrator_test_utils.py +130 -130
- tests/orchestrator/schemas/OrchetrationStateSchema.py +66 -66
- tests/orchestrator/test_call_http.py +235 -176
- tests/orchestrator/test_continue_as_new.py +67 -67
- tests/orchestrator/test_create_timer.py +126 -126
- tests/orchestrator/test_entity.py +397 -395
- tests/orchestrator/test_external_event.py +53 -53
- tests/orchestrator/test_fan_out_fan_in.py +175 -175
- tests/orchestrator/test_is_replaying_flag.py +101 -101
- tests/orchestrator/test_retries.py +308 -308
- tests/orchestrator/test_sequential_orchestrator.py +841 -841
- tests/orchestrator/test_sequential_orchestrator_custom_status.py +119 -119
- tests/orchestrator/test_sequential_orchestrator_with_retry.py +465 -465
- tests/orchestrator/test_serialization.py +30 -30
- tests/orchestrator/test_sub_orchestrator.py +95 -95
- tests/orchestrator/test_sub_orchestrator_with_retry.py +129 -129
- tests/orchestrator/test_task_any.py +60 -60
- tests/tasks/tasks_test_utils.py +17 -17
- tests/tasks/test_long_timers.py +70 -0
- tests/tasks/test_new_uuid.py +34 -34
- tests/test_utils/ContextBuilder.py +174 -174
- tests/test_utils/EntityContextBuilder.py +56 -56
- tests/test_utils/constants.py +1 -1
- tests/test_utils/json_utils.py +30 -30
- tests/test_utils/testClasses.py +56 -56
- tests/utils/__init__.py +1 -0
- tests/utils/test_entity_utils.py +24 -0
- azure_functions_durable-1.2.9.data/data/_manifest/bsi.json +0 -1
- azure_functions_durable-1.2.9.data/data/_manifest/manifest.cat +0 -0
- azure_functions_durable-1.2.9.data/data/_manifest/manifest.spdx.json +0 -11985
- azure_functions_durable-1.2.9.data/data/_manifest/manifest.spdx.json.sha256 +0 -1
- azure_functions_durable-1.2.9.dist-info/RECORD +0 -102
- {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.3.0.dist-info}/top_level.txt +0 -0
|
@@ -1,91 +1,103 @@
|
|
|
1
|
-
class EntityId:
|
|
2
|
-
"""EntityId.
|
|
3
|
-
|
|
4
|
-
It identifies an entity by its name and its key.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
def __init__(self, name: str, key: str):
|
|
8
|
-
"""Instantiate an EntityId object.
|
|
9
|
-
|
|
10
|
-
Identifies an entity by its name and its key.
|
|
11
|
-
|
|
12
|
-
Parameters
|
|
13
|
-
----------
|
|
14
|
-
name: str
|
|
15
|
-
The entity name
|
|
16
|
-
key: str
|
|
17
|
-
The entity key
|
|
18
|
-
|
|
19
|
-
Raises
|
|
20
|
-
------
|
|
21
|
-
ValueError: If the entity name or key are the empty string
|
|
22
|
-
"""
|
|
23
|
-
if name == "":
|
|
24
|
-
raise ValueError("Entity name cannot be empty")
|
|
25
|
-
if key == "":
|
|
26
|
-
raise ValueError("Entity key cannot be empty")
|
|
27
|
-
self.name: str = name
|
|
28
|
-
self.key: str = key
|
|
29
|
-
|
|
30
|
-
@staticmethod
|
|
31
|
-
def get_scheduler_id(entity_id: 'EntityId') -> str:
|
|
32
|
-
"""Produce a SchedulerId from an EntityId.
|
|
33
|
-
|
|
34
|
-
Parameters
|
|
35
|
-
----------
|
|
36
|
-
entity_id: EntityId
|
|
37
|
-
An EntityId object
|
|
38
|
-
|
|
39
|
-
Returns
|
|
40
|
-
-------
|
|
41
|
-
str:
|
|
42
|
-
A SchedulerId representation of the input EntityId
|
|
43
|
-
"""
|
|
44
|
-
return f"@{entity_id.name.lower()}@{entity_id.key}"
|
|
45
|
-
|
|
46
|
-
@staticmethod
|
|
47
|
-
def get_entity_id(scheduler_id: str) -> 'EntityId':
|
|
48
|
-
"""Return an EntityId from a SchedulerId string.
|
|
49
|
-
|
|
50
|
-
Parameters
|
|
51
|
-
----------
|
|
52
|
-
scheduler_id: str
|
|
53
|
-
The SchedulerId in which to base the returned EntityId
|
|
54
|
-
|
|
55
|
-
Raises
|
|
56
|
-
------
|
|
57
|
-
ValueError:
|
|
58
|
-
When the SchedulerId string does not have the expected format
|
|
59
|
-
|
|
60
|
-
Returns
|
|
61
|
-
-------
|
|
62
|
-
EntityId:
|
|
63
|
-
An EntityId object based on the SchedulerId string
|
|
64
|
-
"""
|
|
65
|
-
sched_id_truncated = scheduler_id[1:] # we drop the starting `@`
|
|
66
|
-
components = sched_id_truncated.split("@")
|
|
67
|
-
if len(components) != 2:
|
|
68
|
-
raise ValueError("Unexpected format in SchedulerId")
|
|
69
|
-
[name, key] = components
|
|
70
|
-
return EntityId(name, key)
|
|
71
|
-
|
|
72
|
-
@staticmethod
|
|
73
|
-
def get_entity_id_url_path(entity_id: 'EntityId') -> str:
|
|
74
|
-
"""Print the the entity url path.
|
|
75
|
-
|
|
76
|
-
Returns
|
|
77
|
-
-------
|
|
78
|
-
str:
|
|
79
|
-
A url path of the EntityId
|
|
80
|
-
"""
|
|
81
|
-
return f'entities/{entity_id.name}/{entity_id.key}'
|
|
82
|
-
|
|
83
|
-
def __str__(self) -> str:
|
|
84
|
-
"""Print the string representation of this EntityId.
|
|
85
|
-
|
|
86
|
-
Returns
|
|
87
|
-
-------
|
|
88
|
-
str:
|
|
89
|
-
A SchedulerId-based string representation of the EntityId
|
|
90
|
-
"""
|
|
91
|
-
return EntityId.get_scheduler_id(entity_id=self)
|
|
1
|
+
class EntityId:
|
|
2
|
+
"""EntityId.
|
|
3
|
+
|
|
4
|
+
It identifies an entity by its name and its key.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
def __init__(self, name: str, key: str):
|
|
8
|
+
"""Instantiate an EntityId object.
|
|
9
|
+
|
|
10
|
+
Identifies an entity by its name and its key.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
name: str
|
|
15
|
+
The entity name
|
|
16
|
+
key: str
|
|
17
|
+
The entity key
|
|
18
|
+
|
|
19
|
+
Raises
|
|
20
|
+
------
|
|
21
|
+
ValueError: If the entity name or key are the empty string
|
|
22
|
+
"""
|
|
23
|
+
if name == "":
|
|
24
|
+
raise ValueError("Entity name cannot be empty")
|
|
25
|
+
if key == "":
|
|
26
|
+
raise ValueError("Entity key cannot be empty")
|
|
27
|
+
self.name: str = name
|
|
28
|
+
self.key: str = key
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def get_scheduler_id(entity_id: 'EntityId') -> str:
|
|
32
|
+
"""Produce a SchedulerId from an EntityId.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
entity_id: EntityId
|
|
37
|
+
An EntityId object
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
str:
|
|
42
|
+
A SchedulerId representation of the input EntityId
|
|
43
|
+
"""
|
|
44
|
+
return f"@{entity_id.name.lower()}@{entity_id.key}"
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def get_entity_id(scheduler_id: str) -> 'EntityId':
|
|
48
|
+
"""Return an EntityId from a SchedulerId string.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
scheduler_id: str
|
|
53
|
+
The SchedulerId in which to base the returned EntityId
|
|
54
|
+
|
|
55
|
+
Raises
|
|
56
|
+
------
|
|
57
|
+
ValueError:
|
|
58
|
+
When the SchedulerId string does not have the expected format
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
EntityId:
|
|
63
|
+
An EntityId object based on the SchedulerId string
|
|
64
|
+
"""
|
|
65
|
+
sched_id_truncated = scheduler_id[1:] # we drop the starting `@`
|
|
66
|
+
components = sched_id_truncated.split("@")
|
|
67
|
+
if len(components) != 2:
|
|
68
|
+
raise ValueError("Unexpected format in SchedulerId")
|
|
69
|
+
[name, key] = components
|
|
70
|
+
return EntityId(name, key)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def get_entity_id_url_path(entity_id: 'EntityId') -> str:
|
|
74
|
+
"""Print the the entity url path.
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
str:
|
|
79
|
+
A url path of the EntityId
|
|
80
|
+
"""
|
|
81
|
+
return f'entities/{entity_id.name}/{entity_id.key}'
|
|
82
|
+
|
|
83
|
+
def __str__(self) -> str:
|
|
84
|
+
"""Print the string representation of this EntityId.
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
str:
|
|
89
|
+
A SchedulerId-based string representation of the EntityId
|
|
90
|
+
"""
|
|
91
|
+
return EntityId.get_scheduler_id(entity_id=self)
|
|
92
|
+
|
|
93
|
+
def __eq__(self, other: object) -> bool:
|
|
94
|
+
"""Check if two EntityId objects are equal.
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
other: object
|
|
99
|
+
"""
|
|
100
|
+
if not isinstance(other, EntityId):
|
|
101
|
+
return False
|
|
102
|
+
|
|
103
|
+
return self.name == other.name and self.key == other.key
|
|
@@ -1,69 +1,80 @@
|
|
|
1
|
-
from typing import Any, List, Union
|
|
2
|
-
|
|
3
|
-
import aiohttp
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
async def post_async_request(url: str,
|
|
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
|
-
|
|
1
|
+
from typing import Any, List, Union
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def post_async_request(url: str,
|
|
7
|
+
data: Any = None,
|
|
8
|
+
trace_parent: str = None,
|
|
9
|
+
trace_state: str = None) -> List[Union[int, Any]]:
|
|
10
|
+
"""Post request with the data provided to the url provided.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
url: str
|
|
15
|
+
url to make the post to
|
|
16
|
+
data: Any
|
|
17
|
+
object to post
|
|
18
|
+
trace_parent: str
|
|
19
|
+
traceparent header to send with the request
|
|
20
|
+
trace_state: str
|
|
21
|
+
tracestate header to send with the request
|
|
22
|
+
|
|
23
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
[int, Any]
|
|
26
|
+
Tuple with the Response status code and the data returned from the request
|
|
27
|
+
"""
|
|
28
|
+
async with aiohttp.ClientSession() as session:
|
|
29
|
+
headers = {}
|
|
30
|
+
if trace_parent:
|
|
31
|
+
headers["traceparent"] = trace_parent
|
|
32
|
+
if trace_state:
|
|
33
|
+
headers["tracestate"] = trace_state
|
|
34
|
+
async with session.post(url, json=data, headers=headers) as response:
|
|
35
|
+
# We disable aiohttp's input type validation
|
|
36
|
+
# as the server may respond with alternative
|
|
37
|
+
# data encodings. This is potentially unsafe.
|
|
38
|
+
# More here: https://docs.aiohttp.org/en/stable/client_advanced.html
|
|
39
|
+
data = await response.json(content_type=None)
|
|
40
|
+
return [response.status, data]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
async def get_async_request(url: str) -> List[Any]:
|
|
44
|
+
"""Get the data from the url provided.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
url: str
|
|
49
|
+
url to get the data from
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
[int, Any]
|
|
54
|
+
Tuple with the Response status code and the data returned from the request
|
|
55
|
+
"""
|
|
56
|
+
async with aiohttp.ClientSession() as session:
|
|
57
|
+
async with session.get(url) as response:
|
|
58
|
+
data = await response.json(content_type=None)
|
|
59
|
+
if data is None:
|
|
60
|
+
data = ""
|
|
61
|
+
return [response.status, data]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
async def delete_async_request(url: str) -> List[Union[int, Any]]:
|
|
65
|
+
"""Delete the data from the url provided.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
url: str
|
|
70
|
+
url to delete the data from
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
[int, Any]
|
|
75
|
+
Tuple with the Response status code and the data returned from the request
|
|
76
|
+
"""
|
|
77
|
+
async with aiohttp.ClientSession() as session:
|
|
78
|
+
async with session.delete(url) as response:
|
|
79
|
+
data = await response.json(content_type=None)
|
|
80
|
+
return [response.status, data]
|
|
@@ -1,56 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
from
|
|
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
|
-
|
|
1
|
+
import datetime
|
|
2
|
+
import re
|
|
3
|
+
from typing import Dict, Any
|
|
4
|
+
|
|
5
|
+
from ...constants import DATETIME_STRING_FORMAT
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def add_attrib(json_dict: Dict[str, Any], object_,
|
|
9
|
+
attribute_name: str, alt_name: str = None):
|
|
10
|
+
"""Add the value of the attribute from the object to the dictionary.
|
|
11
|
+
|
|
12
|
+
Used to dynamically add the value of the attribute if the value is present.
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
json_dict: The dictionary to add the attribute to
|
|
17
|
+
object_: The object to look for the attribute on
|
|
18
|
+
attribute_name: The name of the attribute to look for
|
|
19
|
+
alt_name: An alternate name to provide to the attribute in the in the dictionary
|
|
20
|
+
"""
|
|
21
|
+
if hasattr(object_, attribute_name):
|
|
22
|
+
json_dict[alt_name or attribute_name] = \
|
|
23
|
+
getattr(object_, attribute_name)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def add_datetime_attrib(json_dict: Dict[str, Any], object_,
|
|
27
|
+
attribute_name: str, alt_name: str = None):
|
|
28
|
+
"""Add the value of the attribute from the object to the dictionary converted into a string.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
json_dict: The dictionary to add the attribute to
|
|
33
|
+
object_: The object to look for the attribute on
|
|
34
|
+
attribute_name: The name of the attribute to look for
|
|
35
|
+
alt_name: An alternate name to provide to the attribute in the in the dictionary
|
|
36
|
+
"""
|
|
37
|
+
if hasattr(object_, attribute_name):
|
|
38
|
+
json_dict[alt_name or attribute_name] = \
|
|
39
|
+
getattr(object_, attribute_name).strftime(DATETIME_STRING_FORMAT)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# When we recieve properties from WebJobs extension originally parsed as
|
|
43
|
+
# TimeSpan objects through Newtonsoft, the format complies with the constant
|
|
44
|
+
# format specifier for TimeSpan in .NET.
|
|
45
|
+
# Python offers no convenient way to parse these back into timedeltas,
|
|
46
|
+
# so we use this regex method instead
|
|
47
|
+
def parse_timespan_attrib(from_str: str) -> datetime.timedelta:
|
|
48
|
+
"""Convert a string representing TimeSpan.ToString("c") in .NET to a python timedelta.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
from_str: The string format of the TimeSpan to convert
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
timespan.timedelta
|
|
57
|
+
The TimeSpan expressed as a Python datetime.timedelta
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
match = re.match(r"^(?P<negative>-)?(?:(?P<days>[0-9]*)\.)?"
|
|
61
|
+
r"(?P<hours>[0-9]{2}):(?P<minutes>[0-9]{2})"
|
|
62
|
+
r":(?P<seconds>[0-9]{2})(?:\.(?P<ticks>[0-9]{7}))?$",
|
|
63
|
+
from_str)
|
|
64
|
+
if match:
|
|
65
|
+
groups = match.groupdict()
|
|
66
|
+
span = datetime.timedelta(
|
|
67
|
+
days=int(groups['days'] or "0"),
|
|
68
|
+
hours=int(groups['hours']),
|
|
69
|
+
minutes=int(groups['minutes']),
|
|
70
|
+
seconds=int(groups['seconds']),
|
|
71
|
+
microseconds=int(groups['ticks'] or "0") // 10)
|
|
72
|
+
|
|
73
|
+
if groups['negative'] == '-':
|
|
74
|
+
span = -span
|
|
75
|
+
return span
|
|
76
|
+
else:
|
|
77
|
+
raise Exception(f"Format of TimeSpan failed attempted conversion to timedelta: {from_str}")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def add_json_attrib(json_dict: Dict[str, Any], object_,
|
|
81
|
+
attribute_name: str, alt_name: str = None):
|
|
82
|
+
"""Add the results of the to_json() function call of the attribute from the object to the dict.
|
|
83
|
+
|
|
84
|
+
Used to dynamically add the JSON converted value of the attribute if the value is present.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
json_dict: The dictionary to add the attribute to
|
|
89
|
+
object_: The object to look for the attribute on
|
|
90
|
+
attribute_name: The name of the attribute to look for
|
|
91
|
+
alt_name: An alternate name to provide to the attribute in the in the dictionary
|
|
92
|
+
"""
|
|
93
|
+
if hasattr(object_, attribute_name):
|
|
94
|
+
attribute_value = getattr(object_, attribute_name)
|
|
95
|
+
if attribute_value:
|
|
96
|
+
json_dict[alt_name or attribute_name] = attribute_value.to_json()
|
|
@@ -1,71 +1,73 @@
|
|
|
1
|
-
"""Durable Orchestrator.
|
|
2
|
-
|
|
3
|
-
Responsible for orchestrating the execution of the user defined generator
|
|
4
|
-
function.
|
|
5
|
-
"""
|
|
6
|
-
from azure.durable_functions.models.TaskOrchestrationExecutor import TaskOrchestrationExecutor
|
|
7
|
-
from typing import Callable, Any, Generator
|
|
8
|
-
|
|
9
|
-
from .models import DurableOrchestrationContext
|
|
10
|
-
|
|
11
|
-
import azure.functions as func
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class Orchestrator:
|
|
15
|
-
"""Durable Orchestration Class.
|
|
16
|
-
|
|
17
|
-
Responsible for orchestrating the execution of the user defined generator
|
|
18
|
-
function.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
def __init__(self,
|
|
22
|
-
activity_func: Callable[[DurableOrchestrationContext], Generator[Any, Any, Any]]):
|
|
23
|
-
"""Create a new orchestrator for the user defined generator.
|
|
24
|
-
|
|
25
|
-
Responsible for orchestrating the execution of the user defined
|
|
26
|
-
generator function.
|
|
27
|
-
:param activity_func: Generator function to orchestrate.
|
|
28
|
-
"""
|
|
29
|
-
self.fn: Callable[[DurableOrchestrationContext], Generator[Any, Any, Any]] = activity_func
|
|
30
|
-
self.task_orchestration_executor = TaskOrchestrationExecutor()
|
|
31
|
-
|
|
32
|
-
def handle(self, context: DurableOrchestrationContext) -> str:
|
|
33
|
-
"""Handle the orchestration of the user defined generator function.
|
|
34
|
-
|
|
35
|
-
Parameters
|
|
36
|
-
----------
|
|
37
|
-
context : DurableOrchestrationContext
|
|
38
|
-
The DF orchestration context
|
|
39
|
-
|
|
40
|
-
Returns
|
|
41
|
-
-------
|
|
42
|
-
str
|
|
43
|
-
The JSON-formatted string representing the user's orchestration
|
|
44
|
-
state after this invocation
|
|
45
|
-
"""
|
|
46
|
-
self.durable_context = context
|
|
47
|
-
return self.task_orchestration_executor.execute(context, context.histories, self.fn)
|
|
48
|
-
|
|
49
|
-
@classmethod
|
|
50
|
-
def create(cls, fn: Callable[[DurableOrchestrationContext], Generator[Any, Any, Any]]) \
|
|
51
|
-
-> Callable[[Any], str]:
|
|
52
|
-
"""Create an instance of the orchestration class.
|
|
53
|
-
|
|
54
|
-
Parameters
|
|
55
|
-
----------
|
|
56
|
-
fn: Callable[[DurableOrchestrationContext], Iterator[Any]]
|
|
57
|
-
Generator function that needs orchestration
|
|
58
|
-
|
|
59
|
-
Returns
|
|
60
|
-
-------
|
|
61
|
-
Callable[[Any], str]
|
|
62
|
-
Handle function of the newly created orchestration client
|
|
63
|
-
"""
|
|
64
|
-
|
|
65
|
-
def handle(context: func.OrchestrationContext) -> str:
|
|
66
|
-
context_body = getattr(context, "body", None)
|
|
67
|
-
if context_body is None:
|
|
68
|
-
context_body = context
|
|
69
|
-
return Orchestrator(fn).handle(DurableOrchestrationContext.from_json(context_body))
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
"""Durable Orchestrator.
|
|
2
|
+
|
|
3
|
+
Responsible for orchestrating the execution of the user defined generator
|
|
4
|
+
function.
|
|
5
|
+
"""
|
|
6
|
+
from azure.durable_functions.models.TaskOrchestrationExecutor import TaskOrchestrationExecutor
|
|
7
|
+
from typing import Callable, Any, Generator
|
|
8
|
+
|
|
9
|
+
from .models import DurableOrchestrationContext
|
|
10
|
+
|
|
11
|
+
import azure.functions as func
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Orchestrator:
|
|
15
|
+
"""Durable Orchestration Class.
|
|
16
|
+
|
|
17
|
+
Responsible for orchestrating the execution of the user defined generator
|
|
18
|
+
function.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self,
|
|
22
|
+
activity_func: Callable[[DurableOrchestrationContext], Generator[Any, Any, Any]]):
|
|
23
|
+
"""Create a new orchestrator for the user defined generator.
|
|
24
|
+
|
|
25
|
+
Responsible for orchestrating the execution of the user defined
|
|
26
|
+
generator function.
|
|
27
|
+
:param activity_func: Generator function to orchestrate.
|
|
28
|
+
"""
|
|
29
|
+
self.fn: Callable[[DurableOrchestrationContext], Generator[Any, Any, Any]] = activity_func
|
|
30
|
+
self.task_orchestration_executor = TaskOrchestrationExecutor()
|
|
31
|
+
|
|
32
|
+
def handle(self, context: DurableOrchestrationContext) -> str:
|
|
33
|
+
"""Handle the orchestration of the user defined generator function.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
context : DurableOrchestrationContext
|
|
38
|
+
The DF orchestration context
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
str
|
|
43
|
+
The JSON-formatted string representing the user's orchestration
|
|
44
|
+
state after this invocation
|
|
45
|
+
"""
|
|
46
|
+
self.durable_context = context
|
|
47
|
+
return self.task_orchestration_executor.execute(context, context.histories, self.fn)
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def create(cls, fn: Callable[[DurableOrchestrationContext], Generator[Any, Any, Any]]) \
|
|
51
|
+
-> Callable[[Any], str]:
|
|
52
|
+
"""Create an instance of the orchestration class.
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
----------
|
|
56
|
+
fn: Callable[[DurableOrchestrationContext], Iterator[Any]]
|
|
57
|
+
Generator function that needs orchestration
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
Callable[[Any], str]
|
|
62
|
+
Handle function of the newly created orchestration client
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
def handle(context: func.OrchestrationContext) -> str:
|
|
66
|
+
context_body = getattr(context, "body", None)
|
|
67
|
+
if context_body is None:
|
|
68
|
+
context_body = context
|
|
69
|
+
return Orchestrator(fn).handle(DurableOrchestrationContext.from_json(context_body))
|
|
70
|
+
|
|
71
|
+
handle.orchestrator_function = fn
|
|
72
|
+
|
|
73
|
+
return handle
|