azure-functions-durable 1.2.8__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 -711
  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 -29
  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 -333
  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 -25
  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.8.dist-info → azure_functions_durable-1.2.10.dist-info}/LICENSE +21 -21
  57. {azure_functions_durable-1.2.8.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. {azure_functions_durable-1.2.8.dist-info → azure_functions_durable-1.2.10.dist-info}/WHEEL +1 -1
  60. tests/models/test_DecoratorMetadata.py +135 -135
  61. tests/models/test_Decorators.py +107 -107
  62. tests/models/test_DurableOrchestrationBindings.py +68 -56
  63. tests/models/test_DurableOrchestrationClient.py +730 -612
  64. tests/models/test_DurableOrchestrationContext.py +102 -102
  65. tests/models/test_DurableOrchestrationStatus.py +59 -59
  66. tests/models/test_OrchestrationState.py +28 -28
  67. tests/models/test_RpcManagementOptions.py +79 -79
  68. tests/models/test_TokenSource.py +10 -10
  69. tests/orchestrator/models/OrchestrationInstance.py +18 -18
  70. tests/orchestrator/orchestrator_test_utils.py +130 -130
  71. tests/orchestrator/schemas/OrchetrationStateSchema.py +66 -66
  72. tests/orchestrator/test_call_http.py +235 -176
  73. tests/orchestrator/test_continue_as_new.py +67 -67
  74. tests/orchestrator/test_create_timer.py +126 -126
  75. tests/orchestrator/test_entity.py +395 -395
  76. tests/orchestrator/test_external_event.py +53 -53
  77. tests/orchestrator/test_fan_out_fan_in.py +175 -175
  78. tests/orchestrator/test_is_replaying_flag.py +101 -101
  79. tests/orchestrator/test_retries.py +308 -308
  80. tests/orchestrator/test_sequential_orchestrator.py +841 -801
  81. tests/orchestrator/test_sequential_orchestrator_custom_status.py +119 -119
  82. tests/orchestrator/test_sequential_orchestrator_with_retry.py +465 -465
  83. tests/orchestrator/test_serialization.py +30 -30
  84. tests/orchestrator/test_sub_orchestrator.py +95 -95
  85. tests/orchestrator/test_sub_orchestrator_with_retry.py +129 -129
  86. tests/orchestrator/test_task_any.py +60 -60
  87. tests/tasks/tasks_test_utils.py +17 -17
  88. tests/tasks/test_new_uuid.py +34 -34
  89. tests/test_utils/ContextBuilder.py +174 -174
  90. tests/test_utils/EntityContextBuilder.py +56 -56
  91. tests/test_utils/constants.py +1 -1
  92. tests/test_utils/json_utils.py +30 -30
  93. tests/test_utils/testClasses.py +56 -56
  94. tests/utils/__init__.py +1 -0
  95. tests/utils/test_entity_utils.py +24 -0
  96. azure_functions_durable-1.2.8.data/data/_manifest/bsi.json +0 -1
  97. azure_functions_durable-1.2.8.data/data/_manifest/manifest.cat +0 -0
  98. azure_functions_durable-1.2.8.data/data/_manifest/manifest.spdx.json +0 -12845
  99. azure_functions_durable-1.2.8.data/data/_manifest/manifest.spdx.json.sha256 +0 -1
  100. azure_functions_durable-1.2.8.dist-info/RECORD +0 -102
  101. {azure_functions_durable-1.2.8.dist-info → azure_functions_durable-1.2.10.dist-info}/top_level.txt +0 -0
@@ -1,116 +1,117 @@
1
- import json
2
- from typing import List, Any, Dict, Optional, Union
3
-
4
- from azure.durable_functions.models.ReplaySchema import ReplaySchema
5
-
6
- from .utils.json_utils import add_attrib
7
- from azure.durable_functions.models.actions.Action import Action
8
-
9
-
10
- class OrchestratorState:
11
- """Orchestration State.
12
-
13
- Used to communicate the state of the orchestration back to the durable
14
- extension
15
- """
16
-
17
- def __init__(self,
18
- is_done: bool,
19
- actions: List[List[Action]],
20
- output: Any,
21
- replay_schema: ReplaySchema,
22
- error: str = None,
23
- custom_status: Any = None):
24
- self._is_done: bool = is_done
25
- self._actions: List[List[Action]] = actions
26
- self._output: Any = output
27
- self._error: Optional[str] = error
28
- self._custom_status: Any = custom_status
29
- self._replay_schema: ReplaySchema = replay_schema
30
-
31
- @property
32
- def actions(self) -> List[List[Action]]:
33
- """Get the ordered list of async actions the orchestrator function should perform.
34
-
35
- This list is append-only; it must contain all scheduled async actions up to the latest
36
- requested work, even actions that have already been completed.
37
-
38
- Actions are grouped by execution. Each subsequent orchestrator execution should add a
39
- new array of action objects to the collection.
40
- """
41
- return self._actions
42
-
43
- @property
44
- def is_done(self) -> bool:
45
- """Get indicator of whether this is the last execution of this orchestrator instance.
46
-
47
- When this value is true, the Durable Functions extension will consider the orchestration
48
- instance completed and will attempt to return the output value.
49
- """
50
- return self._is_done
51
-
52
- @property
53
- def output(self):
54
- """Get the JSON-serializable value returned by the orchestrator instance completion.
55
-
56
- Optional.
57
- """
58
- return self._output
59
-
60
- @property
61
- def error(self) -> Optional[str]:
62
- """Get the error received when running the orchestration.
63
-
64
- Optional.
65
- """
66
- return self._error
67
-
68
- @property
69
- def custom_status(self):
70
- """Get the JSON-serializable value used by DurableOrchestrationContext.SetCustomStatus."""
71
- return self._custom_status
72
-
73
- @property
74
- def schema_version(self):
75
- """Get the Replay Schema represented in this OrchestratorState payload."""
76
- return self._replay_schema.value
77
-
78
- def to_json(self) -> Dict[str, Union[str, int]]:
79
- """Convert object into a json dictionary.
80
-
81
- Returns
82
- -------
83
- Dict[str, Any]
84
- The instance of the class converted into a json dictionary
85
- """
86
- json_dict: Dict[str, Union[str, int]] = {}
87
- add_attrib(json_dict, self, '_is_done', 'isDone')
88
- if self._replay_schema != ReplaySchema.V1:
89
- add_attrib(json_dict, self, 'schema_version', 'schemaVersion')
90
- self._add_actions(json_dict)
91
- if not (self._output is None):
92
- json_dict['output'] = self._output
93
- if self._error:
94
- json_dict['error'] = self._error
95
- if self._custom_status:
96
- json_dict['customStatus'] = self._custom_status
97
- return json_dict
98
-
99
- def _add_actions(self, json_dict):
100
- json_dict['actions'] = []
101
- for action_list in self._actions:
102
- action_result_list = []
103
- for action_obj in action_list:
104
- action_result_list.append(action_obj.to_json())
105
- json_dict['actions'].append(action_result_list)
106
-
107
- def to_json_string(self) -> str:
108
- """Convert object into a json string.
109
-
110
- Returns
111
- -------
112
- str
113
- The instance of the object in json string format
114
- """
115
- json_dict = self.to_json()
116
- return json.dumps(json_dict)
1
+ import json
2
+ from typing import List, Any, Dict, Optional
3
+
4
+ from azure.durable_functions.models.ReplaySchema import ReplaySchema
5
+
6
+ from .utils.json_utils import add_attrib
7
+ from azure.durable_functions.models.actions.Action import Action
8
+ from azure.functions._durable_functions import _serialize_custom_object
9
+
10
+
11
+ class OrchestratorState:
12
+ """Orchestration State.
13
+
14
+ Used to communicate the state of the orchestration back to the durable
15
+ extension
16
+ """
17
+
18
+ def __init__(self,
19
+ is_done: bool,
20
+ actions: List[List[Action]],
21
+ output: Any,
22
+ replay_schema: ReplaySchema,
23
+ error: str = None,
24
+ custom_status: Any = None):
25
+ self._is_done: bool = is_done
26
+ self._actions: List[List[Action]] = actions
27
+ self._output: Any = output
28
+ self._error: Optional[str] = error
29
+ self._custom_status: Any = custom_status
30
+ self._replay_schema: ReplaySchema = replay_schema
31
+
32
+ @property
33
+ def actions(self) -> List[List[Action]]:
34
+ """Get the ordered list of async actions the orchestrator function should perform.
35
+
36
+ This list is append-only; it must contain all scheduled async actions up to the latest
37
+ requested work, even actions that have already been completed.
38
+
39
+ Actions are grouped by execution. Each subsequent orchestrator execution should add a
40
+ new array of action objects to the collection.
41
+ """
42
+ return self._actions
43
+
44
+ @property
45
+ def is_done(self) -> bool:
46
+ """Get indicator of whether this is the last execution of this orchestrator instance.
47
+
48
+ When this value is true, the Durable Functions extension will consider the orchestration
49
+ instance completed and will attempt to return the output value.
50
+ """
51
+ return self._is_done
52
+
53
+ @property
54
+ def output(self):
55
+ """Get the JSON-serializable value returned by the orchestrator instance completion.
56
+
57
+ Optional.
58
+ """
59
+ return self._output
60
+
61
+ @property
62
+ def error(self) -> Optional[str]:
63
+ """Get the error received when running the orchestration.
64
+
65
+ Optional.
66
+ """
67
+ return self._error
68
+
69
+ @property
70
+ def custom_status(self):
71
+ """Get the JSON-serializable value used by DurableOrchestrationContext.SetCustomStatus."""
72
+ return self._custom_status
73
+
74
+ @property
75
+ def schema_version(self):
76
+ """Get the Replay Schema represented in this OrchestratorState payload."""
77
+ return self._replay_schema.value
78
+
79
+ def to_json(self) -> Dict[str, Any]:
80
+ """Convert object into a json dictionary.
81
+
82
+ Returns
83
+ -------
84
+ Dict[str, Any]
85
+ The instance of the class converted into a json dictionary
86
+ """
87
+ json_dict: Dict[str, Any] = {}
88
+ add_attrib(json_dict, self, '_is_done', 'isDone')
89
+ if self._replay_schema != ReplaySchema.V1:
90
+ add_attrib(json_dict, self, 'schema_version', 'schemaVersion')
91
+ self._add_actions(json_dict)
92
+ if not (self._output is None):
93
+ json_dict['output'] = self._output
94
+ if self._error:
95
+ json_dict['error'] = self._error
96
+ if self._custom_status:
97
+ json_dict['customStatus'] = self._custom_status
98
+ return json_dict
99
+
100
+ def _add_actions(self, json_dict):
101
+ json_dict['actions'] = []
102
+ for action_list in self._actions:
103
+ action_result_list = []
104
+ for action_obj in action_list:
105
+ action_result_list.append(action_obj.to_json())
106
+ json_dict['actions'].append(action_result_list)
107
+
108
+ def to_json_string(self) -> str:
109
+ """Convert object into a json string.
110
+
111
+ Returns
112
+ -------
113
+ str
114
+ The instance of the object in json string format
115
+ """
116
+ json_dict = self.to_json()
117
+ return json.dumps(json_dict, default=_serialize_custom_object)
@@ -1,33 +1,33 @@
1
- from typing import Dict, Any
2
-
3
-
4
- class PurgeHistoryResult:
5
- """Information provided when the request to purge history has been made."""
6
-
7
- # parameter names are as defined by JSON schema and do not conform to PEP8 naming conventions
8
- def __init__(self, instancesDeleted: int, **kwargs):
9
- self._instances_deleted: int = instancesDeleted
10
- if kwargs is not None:
11
- for key, value in kwargs.items():
12
- self.__setattr__(key, value)
13
-
14
- @classmethod
15
- def from_json(cls, json_obj: Dict[Any, Any]):
16
- """Convert the value passed into a new instance of the class.
17
-
18
- Parameters
19
- ----------
20
- json_obj: Dict[Any, Any]
21
- JSON object to be converted into an instance of the class
22
-
23
- Returns
24
- -------
25
- PurgeHistoryResult
26
- New instance of the durable orchestration status class
27
- """
28
- return cls(**json_obj)
29
-
30
- @property
31
- def instances_deleted(self):
32
- """Get the number of deleted instances."""
33
- return self._instances_deleted
1
+ from typing import Dict, Any
2
+
3
+
4
+ class PurgeHistoryResult:
5
+ """Information provided when the request to purge history has been made."""
6
+
7
+ # parameter names are as defined by JSON schema and do not conform to PEP8 naming conventions
8
+ def __init__(self, instancesDeleted: int, **kwargs):
9
+ self._instances_deleted: int = instancesDeleted
10
+ if kwargs is not None:
11
+ for key, value in kwargs.items():
12
+ self.__setattr__(key, value)
13
+
14
+ @classmethod
15
+ def from_json(cls, json_obj: Dict[Any, Any]):
16
+ """Convert the value passed into a new instance of the class.
17
+
18
+ Parameters
19
+ ----------
20
+ json_obj: Dict[Any, Any]
21
+ JSON object to be converted into an instance of the class
22
+
23
+ Returns
24
+ -------
25
+ PurgeHistoryResult
26
+ New instance of the durable orchestration status class
27
+ """
28
+ return cls(**json_obj)
29
+
30
+ @property
31
+ def instances_deleted(self):
32
+ """Get the number of deleted instances."""
33
+ return self._instances_deleted
@@ -1,8 +1,8 @@
1
- from enum import Enum
2
-
3
-
4
- class ReplaySchema(Enum):
5
- """Enum representing the ReplaySchemas supported by this SDK version."""
6
-
7
- V1 = 0
8
- V2 = 1
1
+ from enum import Enum
2
+
3
+
4
+ class ReplaySchema(Enum):
5
+ """Enum representing the ReplaySchemas supported by this SDK version."""
6
+
7
+ V1 = 0
8
+ V2 = 1
@@ -1,69 +1,69 @@
1
- from typing import Dict, Union
2
-
3
- from .utils.json_utils import add_attrib
4
-
5
-
6
- class RetryOptions:
7
- """Retry Options.
8
-
9
- Defines retry policies that can be passed as parameters to various
10
- operations.
11
- """
12
-
13
- def __init__(
14
- self,
15
- first_retry_interval_in_milliseconds: int,
16
- max_number_of_attempts: int):
17
- self._first_retry_interval_in_milliseconds: int = \
18
- first_retry_interval_in_milliseconds
19
- self._max_number_of_attempts: int = max_number_of_attempts
20
-
21
- if self._first_retry_interval_in_milliseconds <= 0:
22
- raise ValueError("first_retry_interval_in_milliseconds value"
23
- "must be greater than 0.")
24
-
25
- @property
26
- def first_retry_interval_in_milliseconds(self) -> int:
27
- """Get the first retry interval (ms).
28
-
29
- Must be greater than 0
30
-
31
- Returns
32
- -------
33
- int
34
- The value indicating the first retry interval
35
- """
36
- return self._first_retry_interval_in_milliseconds
37
-
38
- @property
39
- def max_number_of_attempts(self) -> int:
40
- """Get Max Number of Attempts.
41
-
42
- Returns
43
- -------
44
- int
45
- Value indicating the max number of attempts to retry
46
- """
47
- return self._max_number_of_attempts
48
-
49
- def to_json(self) -> Dict[str, Union[str, int]]:
50
- """Convert object into a json dictionary.
51
-
52
- Returns
53
- -------
54
- Dict[str, Any]
55
- The instance of the class converted into a json dictionary
56
- """
57
- json_dict: Dict[str, Union[str, int]] = {}
58
-
59
- add_attrib(
60
- json_dict,
61
- self,
62
- 'first_retry_interval_in_milliseconds',
63
- 'firstRetryIntervalInMilliseconds')
64
- add_attrib(
65
- json_dict,
66
- self,
67
- 'max_number_of_attempts',
68
- 'maxNumberOfAttempts')
69
- return json_dict
1
+ from typing import Dict, Union
2
+
3
+ from .utils.json_utils import add_attrib
4
+
5
+
6
+ class RetryOptions:
7
+ """Retry Options.
8
+
9
+ Defines retry policies that can be passed as parameters to various
10
+ operations.
11
+ """
12
+
13
+ def __init__(
14
+ self,
15
+ first_retry_interval_in_milliseconds: int,
16
+ max_number_of_attempts: int):
17
+ self._first_retry_interval_in_milliseconds: int = \
18
+ first_retry_interval_in_milliseconds
19
+ self._max_number_of_attempts: int = max_number_of_attempts
20
+
21
+ if self._first_retry_interval_in_milliseconds <= 0:
22
+ raise ValueError("first_retry_interval_in_milliseconds value"
23
+ "must be greater than 0.")
24
+
25
+ @property
26
+ def first_retry_interval_in_milliseconds(self) -> int:
27
+ """Get the first retry interval (ms).
28
+
29
+ Must be greater than 0
30
+
31
+ Returns
32
+ -------
33
+ int
34
+ The value indicating the first retry interval
35
+ """
36
+ return self._first_retry_interval_in_milliseconds
37
+
38
+ @property
39
+ def max_number_of_attempts(self) -> int:
40
+ """Get Max Number of Attempts.
41
+
42
+ Returns
43
+ -------
44
+ int
45
+ Value indicating the max number of attempts to retry
46
+ """
47
+ return self._max_number_of_attempts
48
+
49
+ def to_json(self) -> Dict[str, Union[str, int]]:
50
+ """Convert object into a json dictionary.
51
+
52
+ Returns
53
+ -------
54
+ Dict[str, Any]
55
+ The instance of the class converted into a json dictionary
56
+ """
57
+ json_dict: Dict[str, Union[str, int]] = {}
58
+
59
+ add_attrib(
60
+ json_dict,
61
+ self,
62
+ 'first_retry_interval_in_milliseconds',
63
+ 'firstRetryIntervalInMilliseconds')
64
+ add_attrib(
65
+ json_dict,
66
+ self,
67
+ 'max_number_of_attempts',
68
+ 'maxNumberOfAttempts')
69
+ return json_dict
@@ -1,86 +1,86 @@
1
- from datetime import datetime
2
- from typing import Any, List, Optional
3
-
4
- from azure.durable_functions.constants import DATETIME_STRING_FORMAT
5
- from azure.durable_functions.models.OrchestrationRuntimeStatus import OrchestrationRuntimeStatus
6
-
7
- from .utils.entity_utils import EntityId
8
-
9
-
10
- class RpcManagementOptions:
11
- """Class used to collect the options for getting orchestration status."""
12
-
13
- def __init__(self, instance_id: str = None, task_hub_name: str = None,
14
- connection_name: str = None, show_history: bool = None,
15
- show_history_output: bool = None, created_time_from: datetime = None,
16
- created_time_to: datetime = None,
17
- runtime_status: List[OrchestrationRuntimeStatus] = None, show_input: bool = None,
18
- operation_name: str = None,
19
- entity_Id: EntityId = None):
20
- self._instance_id = instance_id
21
- self._task_hub_name = task_hub_name
22
- self._connection_name = connection_name
23
- self._show_history = show_history
24
- self._show_history_output = show_history_output
25
- self._created_time_from = created_time_from
26
- self._created_time_to = created_time_to
27
- self._runtime_status = runtime_status
28
- self._show_input = show_input
29
- self.operation_name = operation_name
30
- self.entity_Id = entity_Id
31
-
32
- @staticmethod
33
- def _add_arg(query: List[str], name: str, value: Any):
34
- if value:
35
- query.append(f'{name}={value}')
36
-
37
- @staticmethod
38
- def _add_date_arg(query: List[str], name: str, value: Optional[datetime]):
39
- if value:
40
- date_as_string = value.strftime(DATETIME_STRING_FORMAT)
41
- RpcManagementOptions._add_arg(query, name, date_as_string)
42
-
43
- def to_url(self, base_url: Optional[str]) -> str:
44
- """Get the url based on the options selected.
45
-
46
- Parameters
47
- ----------
48
- base_url: str
49
- The base url to prepend to the url path
50
-
51
- Raises
52
- ------
53
- ValueError
54
- When the `base_url` argument is None
55
-
56
- Returns
57
- -------
58
- str
59
- The Url used to get orchestration status information
60
- """
61
- if base_url is None:
62
- raise ValueError("orchestration bindings has not RPC base url")
63
-
64
- if self.entity_Id:
65
- url = f'{base_url}{EntityId.get_entity_id_url_path(self.entity_Id)}'
66
- else:
67
- url = f"{base_url}instances/{self._instance_id if self._instance_id else ''}"
68
-
69
- query: List[str] = []
70
-
71
- self._add_arg(query, 'taskHub', self._task_hub_name)
72
- self._add_arg(query, 'connectionName', self._connection_name)
73
- self._add_arg(query, 'showInput', self._show_input)
74
- self._add_arg(query, 'showHistory', self._show_history)
75
- self._add_arg(query, 'showHistoryOutput', self._show_history_output)
76
- self._add_date_arg(query, 'createdTimeFrom', self._created_time_from)
77
- self._add_date_arg(query, 'createdTimeTo', self._created_time_to)
78
- self._add_arg(query, 'op', self.operation_name)
79
- if self._runtime_status is not None and len(self._runtime_status) > 0:
80
- runtime_status = ",".join(r.value for r in self._runtime_status)
81
- self._add_arg(query, 'runtimeStatus', runtime_status)
82
-
83
- if len(query) > 0:
84
- url += "?" + "&".join(query)
85
-
86
- return url
1
+ from datetime import datetime
2
+ from typing import Any, List, Optional
3
+
4
+ from azure.durable_functions.constants import DATETIME_STRING_FORMAT
5
+ from azure.durable_functions.models.OrchestrationRuntimeStatus import OrchestrationRuntimeStatus
6
+
7
+ from .utils.entity_utils import EntityId
8
+
9
+
10
+ class RpcManagementOptions:
11
+ """Class used to collect the options for getting orchestration status."""
12
+
13
+ def __init__(self, instance_id: str = None, task_hub_name: str = None,
14
+ connection_name: str = None, show_history: bool = None,
15
+ show_history_output: bool = None, created_time_from: datetime = None,
16
+ created_time_to: datetime = None,
17
+ runtime_status: List[OrchestrationRuntimeStatus] = None, show_input: bool = None,
18
+ operation_name: str = None,
19
+ entity_Id: EntityId = None):
20
+ self._instance_id = instance_id
21
+ self._task_hub_name = task_hub_name
22
+ self._connection_name = connection_name
23
+ self._show_history = show_history
24
+ self._show_history_output = show_history_output
25
+ self._created_time_from = created_time_from
26
+ self._created_time_to = created_time_to
27
+ self._runtime_status = runtime_status
28
+ self._show_input = show_input
29
+ self.operation_name = operation_name
30
+ self.entity_Id = entity_Id
31
+
32
+ @staticmethod
33
+ def _add_arg(query: List[str], name: str, value: Any):
34
+ if value:
35
+ query.append(f'{name}={value}')
36
+
37
+ @staticmethod
38
+ def _add_date_arg(query: List[str], name: str, value: Optional[datetime]):
39
+ if value:
40
+ date_as_string = value.strftime(DATETIME_STRING_FORMAT)
41
+ RpcManagementOptions._add_arg(query, name, date_as_string)
42
+
43
+ def to_url(self, base_url: Optional[str]) -> str:
44
+ """Get the url based on the options selected.
45
+
46
+ Parameters
47
+ ----------
48
+ base_url: str
49
+ The base url to prepend to the url path
50
+
51
+ Raises
52
+ ------
53
+ ValueError
54
+ When the `base_url` argument is None
55
+
56
+ Returns
57
+ -------
58
+ str
59
+ The Url used to get orchestration status information
60
+ """
61
+ if base_url is None:
62
+ raise ValueError("orchestration bindings has not RPC base url")
63
+
64
+ if self.entity_Id:
65
+ url = f'{base_url}{EntityId.get_entity_id_url_path(self.entity_Id)}'
66
+ else:
67
+ url = f"{base_url}instances/{self._instance_id if self._instance_id else ''}"
68
+
69
+ query: List[str] = []
70
+
71
+ self._add_arg(query, 'taskHub', self._task_hub_name)
72
+ self._add_arg(query, 'connectionName', self._connection_name)
73
+ self._add_arg(query, 'showInput', self._show_input)
74
+ self._add_arg(query, 'showHistory', self._show_history)
75
+ self._add_arg(query, 'showHistoryOutput', self._show_history_output)
76
+ self._add_date_arg(query, 'createdTimeFrom', self._created_time_from)
77
+ self._add_date_arg(query, 'createdTimeTo', self._created_time_to)
78
+ self._add_arg(query, 'op', self.operation_name)
79
+ if self._runtime_status is not None and len(self._runtime_status) > 0:
80
+ runtime_status = ",".join(r.value for r in self._runtime_status)
81
+ self._add_arg(query, 'runtimeStatus', runtime_status)
82
+
83
+ if len(query) > 0:
84
+ url += "?" + "&".join(query)
85
+
86
+ return url