Skip to content

Commit 4cd7257

Browse files
committed
Docstrings for several api level objects
OchrestrationState, Task, TaskSet, clean up some excess docstrings
1 parent 94cd7ce commit 4cd7257

14 files changed

+92
-185
lines changed

.flake8

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[flake8]
2-
# delete D100~D107 for docstring checks
2+
# delete D100 for docstring checks, promotes redundant documentation of what's in class docstring
33
# W503 contradicts with pep8 and will soon be fixed by flake8
4-
ignore = W503
4+
ignore = W503, D100
55
max-line-length = 99
6+
docstring-convention = numpy
67
exclude =
78
__pycache__,
89
azure/durable_functions/grpc/protobuf/
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"""Defines the base interface for Actions that need to be executed."""
21
from ..models.actions import ActionType
32

43

54
class IAction:
65
"""Defines the base interface for Actions that need to be executed."""
76

87
def __init__(self):
9-
"""Create a new Action object."""
108
actionType: ActionType
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"""Interface for the Orchestration object exposed to the generator function."""
21
from ..models import DurableOrchestrationContext
32

43

54
class IFunctionContext:
6-
"""Orchestration object exposed to the generator function."""
5+
"""Interface for the Orchestration object exposed to the generator function."""
76

87
def __init__(self, df=None):
9-
"""Create a new orchestration context."""
108
self.df: DurableOrchestrationContext = df

azure/durable_functions/models/DurableOrchestrationBindings.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"""Binding information for durable functions."""
21
import json
32
from typing import Dict
43

@@ -11,7 +10,6 @@ class DurableOrchestrationBindings:
1110
"""
1211

1312
def __init__(self, client_data: str):
14-
"""Create a new binding object."""
1513
context = json.loads(client_data)
1614
self.task_hub_name: str = context.get('taskHubName')
1715
self.creation_urls: Dict[str, str] = context.get('creationUrls')

azure/durable_functions/models/DurableOrchestrationClient.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"""Durable Orchestration Client class definition."""
21
import requests
32
import json
43
from typing import List
@@ -14,11 +13,6 @@ class DurableOrchestrationClient:
1413
"""
1514

1615
def __init__(self, context: str):
17-
"""Create a new Orchestration Client.
18-
19-
:param context: The object representing the orchestrationClient input
20-
binding of the Azure function that will use this client.
21-
"""
2216
self.task_hub_name: str
2317
self._uniqueWebHookOrigins: List[str]
2418
self._event_name_placeholder: str = "{eventName}"
@@ -65,9 +59,7 @@ def _get_json_input(client_input: object) -> object:
6559
return json.dumps(client_input) if client_input is not None else None
6660

6761
def _get_start_new_url(self, instance_id, orchestration_function_name):
68-
request_url = self._orchestration_bindings.creation_urls[
69-
'createNewInstancePostUri'
70-
]
62+
request_url = self._orchestration_bindings.creation_urls['createNewInstancePostUri']
7163
request_url = request_url.replace(self._function_name_placeholder,
7264
orchestration_function_name)
7365
request_url = request_url.replace(self._instance_id_placeholder,

azure/durable_functions/models/DurableOrchestrationContext.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"""Defines the Durable Orchestration Context Class Object."""
21
import json
32
import logging
43
import datetime

azure/durable_functions/models/OrchestratorState.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"""Defines the Orchestration State Class structure."""
21
import json
32
from typing import List, Any, Dict
43

@@ -24,6 +23,40 @@ def __init__(self,
2423
self._error: str = error
2524
self._custom_status: Any = custom_status
2625

26+
@property
27+
def actions(self) -> List[List[Any]]:
28+
"""Get the ordered list of async actions the orchestrator function should perform.
29+
30+
This list is append-only; it must contain all scheduled async actions up to the latest
31+
requested work, even actions that have already been completed.
32+
33+
Actions are grouped by execution. Each subsequent orchestrator execution should add a
34+
new array of action objects to the collection.
35+
"""
36+
return self._actions
37+
38+
@property
39+
def is_done(self) -> bool:
40+
"""Get indicator of whether this is the last execution of this orchestrator instance.
41+
42+
When this value is true, the Durable Functions extension will consider the orchestration
43+
instance completed and will attempt to return the output value.
44+
"""
45+
return self._is_done
46+
47+
@property
48+
def output(self):
49+
"""Get the JSON-serializable value returned by the orchestrator instance completion.
50+
51+
Optional.
52+
"""
53+
return self._output
54+
55+
@property
56+
def custom_status(self):
57+
"""Get the JSON-serializable value used by DurableOrchestrationContext.SetCustomStatus."""
58+
return self._custom_status
59+
2760
def to_json(self) -> Dict[str, Any]:
2861
"""Convert object into a json dictionary.
2962

azure/durable_functions/models/RetryOptions.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"""Define the Retry Options class."""
21
from typing import Any, Dict
32

43
from .utils.json_utils import add_attrib

azure/durable_functions/models/Task.py

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Task:
1414
are useful for parallelization and timeout operations in conjunction with
1515
Task.all and Task.any.
1616
"""
17-
_action: IAction
1817

1918
def __init__(self, is_completed, is_faulted, action,
2019
result=None, timestamp=None, id_=None, exc=None):
@@ -37,7 +36,6 @@ def is_completed(self) -> bool:
3736
@property
3837
def is_faulted(self) -> bool:
3938
"""Get indicator whether the task faulted in some way due to error."""
40-
4139
return self._is_faulted
4240

4341
@property

azure/durable_functions/models/TaskSet.py

+52-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,55 @@
33

44

55
class TaskSet:
6-
def __init__(self, isCompleted, actions, result, isFaulted=False, e=None):
7-
self.isCompleted: bool = isCompleted
8-
self.actions: List[IAction] = actions
9-
self.result = result
10-
self.isFaulted: bool = isFaulted
11-
self.exception = e
6+
"""Represents a list of some pending action.
7+
8+
Similar to a native JavaScript promise in
9+
that it acts as a placeholder for outstanding asynchronous work, but has
10+
a synchronous implementation and is specific to Durable Functions.
11+
12+
Tasks are only returned to an orchestration function when a
13+
[[DurableOrchestrationContext]] operation is not called with `yield`. They
14+
are useful for parallelization and timeout operations in conjunction with
15+
Task.all and Task.any.
16+
"""
17+
18+
def __init__(self, is_completed, actions, result, is_faulted=False, exception=None):
19+
self._is_completed: bool = is_completed
20+
self._actions: List[IAction] = actions
21+
self._result = result
22+
self._is_faulted: bool = is_faulted
23+
self._exception = exception
24+
25+
@property
26+
def is_completed(self) -> bool:
27+
"""Get indicator whether the task has completed.
28+
29+
Note that completion is not equivalent to success.
30+
"""
31+
return self._is_completed
32+
33+
@property
34+
def is_faulted(self) -> bool:
35+
"""Get indicator whether the task faulted in some way due to error."""
36+
return self._is_faulted
37+
38+
@property
39+
def actions(self) -> IAction:
40+
"""Get the scheduled action represented by the task.
41+
42+
_Internal use only._
43+
"""
44+
return self._actions
45+
46+
@property
47+
def result(self) -> object:
48+
"""Get the result of the task, if completed. Otherwise `None`."""
49+
return self._result
50+
51+
@property
52+
def exception(self):
53+
"""Get the error thrown when attempting to perform the task's action.
54+
55+
If the Task has not yet completed or has completed successfully, `None`
56+
"""
57+
return self._exception

azure/durable_functions/tasks/call_activity_with_retry.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import logging
21
from typing import List, Any
32
import logging
43

tests/orchestrator/test_sequential_orchestrator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def base_expected_state(output=None) -> OrchestratorState:
2626

2727
def add_hello_action(state: OrchestratorState, input_: str):
2828
action = CallActivityAction(function_name='Hello', input_=input_)
29-
state._actions.append([action])
29+
state.actions.append([action])
3030

3131

3232
def add_hello_completed_events(

tests/tasks/__init__.py

Whitespace-only changes.

tests/tasks/test_call_activity.py

-154
This file was deleted.

0 commit comments

Comments
 (0)