azure-functions-durable 1.2.9__py3-none-any.whl → 1.2.10__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 (101) 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 +249 -249
  5. azure/durable_functions/decorators/metadata.py +109 -109
  6. azure/durable_functions/entity.py +125 -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 +781 -781
  11. azure/durable_functions/models/DurableOrchestrationContext.py +722 -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 +8 -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 +426 -426
  22. azure/durable_functions/models/TaskOrchestrationExecutor.py +346 -336
  23. azure/durable_functions/models/TokenSource.py +56 -56
  24. azure/durable_functions/models/__init__.py +24 -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 +76 -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 +69 -69
  54. azure/durable_functions/models/utils/json_utils.py +56 -56
  55. azure/durable_functions/orchestrator.py +71 -71
  56. {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.2.10.dist-info}/LICENSE +21 -21
  57. {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.2.10.dist-info}/METADATA +58 -58
  58. azure_functions_durable-1.2.10.dist-info/RECORD +100 -0
  59. tests/models/test_DecoratorMetadata.py +135 -135
  60. tests/models/test_Decorators.py +107 -107
  61. tests/models/test_DurableOrchestrationBindings.py +68 -68
  62. tests/models/test_DurableOrchestrationClient.py +730 -730
  63. tests/models/test_DurableOrchestrationContext.py +102 -102
  64. tests/models/test_DurableOrchestrationStatus.py +59 -59
  65. tests/models/test_OrchestrationState.py +28 -28
  66. tests/models/test_RpcManagementOptions.py +79 -79
  67. tests/models/test_TokenSource.py +10 -10
  68. tests/orchestrator/models/OrchestrationInstance.py +18 -18
  69. tests/orchestrator/orchestrator_test_utils.py +130 -130
  70. tests/orchestrator/schemas/OrchetrationStateSchema.py +66 -66
  71. tests/orchestrator/test_call_http.py +235 -176
  72. tests/orchestrator/test_continue_as_new.py +67 -67
  73. tests/orchestrator/test_create_timer.py +126 -126
  74. tests/orchestrator/test_entity.py +395 -395
  75. tests/orchestrator/test_external_event.py +53 -53
  76. tests/orchestrator/test_fan_out_fan_in.py +175 -175
  77. tests/orchestrator/test_is_replaying_flag.py +101 -101
  78. tests/orchestrator/test_retries.py +308 -308
  79. tests/orchestrator/test_sequential_orchestrator.py +841 -841
  80. tests/orchestrator/test_sequential_orchestrator_custom_status.py +119 -119
  81. tests/orchestrator/test_sequential_orchestrator_with_retry.py +465 -465
  82. tests/orchestrator/test_serialization.py +30 -30
  83. tests/orchestrator/test_sub_orchestrator.py +95 -95
  84. tests/orchestrator/test_sub_orchestrator_with_retry.py +129 -129
  85. tests/orchestrator/test_task_any.py +60 -60
  86. tests/tasks/tasks_test_utils.py +17 -17
  87. tests/tasks/test_new_uuid.py +34 -34
  88. tests/test_utils/ContextBuilder.py +174 -174
  89. tests/test_utils/EntityContextBuilder.py +56 -56
  90. tests/test_utils/constants.py +1 -1
  91. tests/test_utils/json_utils.py +30 -30
  92. tests/test_utils/testClasses.py +56 -56
  93. tests/utils/__init__.py +1 -0
  94. tests/utils/test_entity_utils.py +24 -0
  95. azure_functions_durable-1.2.9.data/data/_manifest/bsi.json +0 -1
  96. azure_functions_durable-1.2.9.data/data/_manifest/manifest.cat +0 -0
  97. azure_functions_durable-1.2.9.data/data/_manifest/manifest.spdx.json +0 -11985
  98. azure_functions_durable-1.2.9.data/data/_manifest/manifest.spdx.json.sha256 +0 -1
  99. azure_functions_durable-1.2.9.dist-info/RECORD +0 -102
  100. {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.2.10.dist-info}/WHEEL +0 -0
  101. {azure_functions_durable-1.2.9.dist-info → azure_functions_durable-1.2.10.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,69 @@
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, 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,56 +1,56 @@
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
+ 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,71 +1,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
- 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
+ return handle
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 Katy Shimizu
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Katy Shimizu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.