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.
Files changed (104) hide show
  1. azure/durable_functions/__init__.py +81 -81
  2. azure/durable_functions/constants.py +9 -9
  3. azure/durable_functions/decorators/__init__.py +3 -3
  4. azure/durable_functions/decorators/durable_app.py +260 -249
  5. azure/durable_functions/decorators/metadata.py +109 -109
  6. azure/durable_functions/entity.py +129 -125
  7. azure/durable_functions/models/DurableEntityContext.py +201 -201
  8. azure/durable_functions/models/DurableHttpRequest.py +58 -58
  9. azure/durable_functions/models/DurableOrchestrationBindings.py +66 -66
  10. azure/durable_functions/models/DurableOrchestrationClient.py +812 -781
  11. azure/durable_functions/models/DurableOrchestrationContext.py +761 -707
  12. azure/durable_functions/models/DurableOrchestrationStatus.py +156 -156
  13. azure/durable_functions/models/EntityStateResponse.py +23 -23
  14. azure/durable_functions/models/FunctionContext.py +7 -7
  15. azure/durable_functions/models/OrchestrationRuntimeStatus.py +32 -32
  16. azure/durable_functions/models/OrchestratorState.py +117 -116
  17. azure/durable_functions/models/PurgeHistoryResult.py +33 -33
  18. azure/durable_functions/models/ReplaySchema.py +9 -8
  19. azure/durable_functions/models/RetryOptions.py +69 -69
  20. azure/durable_functions/models/RpcManagementOptions.py +86 -86
  21. azure/durable_functions/models/Task.py +540 -426
  22. azure/durable_functions/models/TaskOrchestrationExecutor.py +352 -336
  23. azure/durable_functions/models/TokenSource.py +56 -56
  24. azure/durable_functions/models/__init__.py +26 -24
  25. azure/durable_functions/models/actions/Action.py +23 -23
  26. azure/durable_functions/models/actions/ActionType.py +18 -18
  27. azure/durable_functions/models/actions/CallActivityAction.py +41 -41
  28. azure/durable_functions/models/actions/CallActivityWithRetryAction.py +45 -45
  29. azure/durable_functions/models/actions/CallEntityAction.py +46 -46
  30. azure/durable_functions/models/actions/CallHttpAction.py +35 -35
  31. azure/durable_functions/models/actions/CallSubOrchestratorAction.py +40 -40
  32. azure/durable_functions/models/actions/CallSubOrchestratorWithRetryAction.py +44 -44
  33. azure/durable_functions/models/actions/CompoundAction.py +35 -35
  34. azure/durable_functions/models/actions/ContinueAsNewAction.py +36 -36
  35. azure/durable_functions/models/actions/CreateTimerAction.py +48 -48
  36. azure/durable_functions/models/actions/NoOpAction.py +35 -35
  37. azure/durable_functions/models/actions/SignalEntityAction.py +47 -47
  38. azure/durable_functions/models/actions/WaitForExternalEventAction.py +63 -63
  39. azure/durable_functions/models/actions/WhenAllAction.py +14 -14
  40. azure/durable_functions/models/actions/WhenAnyAction.py +14 -14
  41. azure/durable_functions/models/actions/__init__.py +24 -24
  42. azure/durable_functions/models/entities/EntityState.py +74 -74
  43. azure/durable_functions/models/entities/OperationResult.py +94 -76
  44. azure/durable_functions/models/entities/RequestMessage.py +53 -53
  45. azure/durable_functions/models/entities/ResponseMessage.py +48 -48
  46. azure/durable_functions/models/entities/Signal.py +62 -62
  47. azure/durable_functions/models/entities/__init__.py +17 -17
  48. azure/durable_functions/models/history/HistoryEvent.py +92 -92
  49. azure/durable_functions/models/history/HistoryEventType.py +27 -27
  50. azure/durable_functions/models/history/__init__.py +8 -8
  51. azure/durable_functions/models/utils/__init__.py +7 -7
  52. azure/durable_functions/models/utils/entity_utils.py +103 -91
  53. azure/durable_functions/models/utils/http_utils.py +80 -69
  54. azure/durable_functions/models/utils/json_utils.py +96 -56
  55. azure/durable_functions/orchestrator.py +73 -71
  56. azure/durable_functions/testing/OrchestratorGeneratorWrapper.py +42 -0
  57. azure/durable_functions/testing/__init__.py +6 -0
  58. {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.3.0.dist-info}/LICENSE +21 -21
  59. {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.3.0.dist-info}/METADATA +59 -58
  60. azure_functions_durable-1.3.0.dist-info/RECORD +103 -0
  61. {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.3.0.dist-info}/WHEEL +1 -1
  62. tests/models/test_DecoratorMetadata.py +135 -135
  63. tests/models/test_Decorators.py +107 -107
  64. tests/models/test_DurableOrchestrationBindings.py +68 -68
  65. tests/models/test_DurableOrchestrationClient.py +730 -730
  66. tests/models/test_DurableOrchestrationContext.py +102 -102
  67. tests/models/test_DurableOrchestrationStatus.py +59 -59
  68. tests/models/test_OrchestrationState.py +28 -28
  69. tests/models/test_RpcManagementOptions.py +79 -79
  70. tests/models/test_TokenSource.py +10 -10
  71. tests/orchestrator/models/OrchestrationInstance.py +18 -18
  72. tests/orchestrator/orchestrator_test_utils.py +130 -130
  73. tests/orchestrator/schemas/OrchetrationStateSchema.py +66 -66
  74. tests/orchestrator/test_call_http.py +235 -176
  75. tests/orchestrator/test_continue_as_new.py +67 -67
  76. tests/orchestrator/test_create_timer.py +126 -126
  77. tests/orchestrator/test_entity.py +397 -395
  78. tests/orchestrator/test_external_event.py +53 -53
  79. tests/orchestrator/test_fan_out_fan_in.py +175 -175
  80. tests/orchestrator/test_is_replaying_flag.py +101 -101
  81. tests/orchestrator/test_retries.py +308 -308
  82. tests/orchestrator/test_sequential_orchestrator.py +841 -841
  83. tests/orchestrator/test_sequential_orchestrator_custom_status.py +119 -119
  84. tests/orchestrator/test_sequential_orchestrator_with_retry.py +465 -465
  85. tests/orchestrator/test_serialization.py +30 -30
  86. tests/orchestrator/test_sub_orchestrator.py +95 -95
  87. tests/orchestrator/test_sub_orchestrator_with_retry.py +129 -129
  88. tests/orchestrator/test_task_any.py +60 -60
  89. tests/tasks/tasks_test_utils.py +17 -17
  90. tests/tasks/test_long_timers.py +70 -0
  91. tests/tasks/test_new_uuid.py +34 -34
  92. tests/test_utils/ContextBuilder.py +174 -174
  93. tests/test_utils/EntityContextBuilder.py +56 -56
  94. tests/test_utils/constants.py +1 -1
  95. tests/test_utils/json_utils.py +30 -30
  96. tests/test_utils/testClasses.py +56 -56
  97. tests/utils/__init__.py +1 -0
  98. tests/utils/test_entity_utils.py +24 -0
  99. azure_functions_durable-1.2.9.data/data/_manifest/bsi.json +0 -1
  100. azure_functions_durable-1.2.9.data/data/_manifest/manifest.cat +0 -0
  101. azure_functions_durable-1.2.9.data/data/_manifest/manifest.spdx.json +0 -11985
  102. azure_functions_durable-1.2.9.data/data/_manifest/manifest.spdx.json.sha256 +0 -1
  103. azure_functions_durable-1.2.9.dist-info/RECORD +0 -102
  104. {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, data: Any = None) -> List[Union[int, Any]]:
7
- """Post request with the data provided to the url provided.
8
-
9
- Parameters
10
- ----------
11
- url: str
12
- url to make the post to
13
- data: Any
14
- object to post
15
-
16
- Returns
17
- -------
18
- [int, Any]
19
- Tuple with the Response status code and the data returned from the request
20
- """
21
- async with aiohttp.ClientSession() as session:
22
- async with session.post(url,
23
- json=data) as response:
24
- # We disable aiohttp's input type validation
25
- # as the server may respond with alternative
26
- # data encodings. This is potentially unsafe.
27
- # More here: https://docs.aiohttp.org/en/stable/client_advanced.html
28
- data = await response.json(content_type=None)
29
- return [response.status, data]
30
-
31
-
32
- async def get_async_request(url: str) -> List[Any]:
33
- """Get the data from the url provided.
34
-
35
- Parameters
36
- ----------
37
- url: str
38
- url to get the data from
39
-
40
- Returns
41
- -------
42
- [int, Any]
43
- Tuple with the Response status code and the data returned from the request
44
- """
45
- async with aiohttp.ClientSession() as session:
46
- async with session.get(url) as response:
47
- data = await response.json(content_type=None)
48
- if data is None:
49
- data = ""
50
- return [response.status, data]
51
-
52
-
53
- async def delete_async_request(url: str) -> List[Union[int, Any]]:
54
- """Delete the data from the url provided.
55
-
56
- Parameters
57
- ----------
58
- url: str
59
- url to delete the data from
60
-
61
- Returns
62
- -------
63
- [int, Any]
64
- Tuple with the Response status code and the data returned from the request
65
- """
66
- async with aiohttp.ClientSession() as session:
67
- async with session.delete(url) as response:
68
- data = await response.json(content_type=None)
69
- return [response.status, data]
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
- from typing import Dict, Any
2
-
3
- from ...constants import DATETIME_STRING_FORMAT
4
-
5
-
6
- def add_attrib(json_dict: Dict[str, Any], object_,
7
- attribute_name: str, alt_name: str = None):
8
- """Add the value of the attribute from the object to the dictionary.
9
-
10
- Used to dynamically add the value of the attribute if the value is present.
11
-
12
- Parameters
13
- ----------
14
- json_dict: The dictionary to add the attribute to
15
- object_: The object to look for the attribute on
16
- attribute_name: The name of the attribute to look for
17
- alt_name: An alternate name to provide to the attribute in the in the dictionary
18
- """
19
- if hasattr(object_, attribute_name):
20
- json_dict[alt_name or attribute_name] = \
21
- getattr(object_, attribute_name)
22
-
23
-
24
- def add_datetime_attrib(json_dict: Dict[str, Any], object_,
25
- attribute_name: str, alt_name: str = None):
26
- """Add the value of the attribute from the object to the dictionary converted into a string.
27
-
28
- Parameters
29
- ----------
30
- json_dict: The dictionary to add the attribute to
31
- object_: The object to look for the attribute on
32
- attribute_name: The name of the attribute to look for
33
- alt_name: An alternate name to provide to the attribute in the in the dictionary
34
- """
35
- if hasattr(object_, attribute_name):
36
- json_dict[alt_name or attribute_name] = \
37
- getattr(object_, attribute_name).strftime(DATETIME_STRING_FORMAT)
38
-
39
-
40
- def add_json_attrib(json_dict: Dict[str, Any], object_,
41
- attribute_name: str, alt_name: str = None):
42
- """Add the results of the to_json() function call of the attribute from the object to the dict.
43
-
44
- Used to dynamically add the JSON converted value of the attribute if the value is present.
45
-
46
- Parameters
47
- ----------
48
- json_dict: The dictionary to add the attribute to
49
- object_: The object to look for the attribute on
50
- attribute_name: The name of the attribute to look for
51
- alt_name: An alternate name to provide to the attribute in the in the dictionary
52
- """
53
- if hasattr(object_, attribute_name):
54
- attribute_value = getattr(object_, attribute_name)
55
- if attribute_value:
56
- json_dict[alt_name or attribute_name] = attribute_value.to_json()
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
- return handle
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