Skip to content

Commit 8da0ac3

Browse files
authored
Enable Singleton Pattern in Durable Orchestration (#115)
1 parent 20b4387 commit 8da0ac3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

azure/durable_functions/models/DurableOrchestrationStatus.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ def __init__(self, name: str = None, instanceId: str = None, createdTime: str =
3131
for key, value in kwargs.items():
3232
self.__setattr__(key, value)
3333

34+
def __bool__(self):
35+
"""Determine if a class resolves to True or False.
36+
37+
We say that a DurableOrchestrationStatus if False if it has a value
38+
`None` for its `_created_time` value, which should be empty if it
39+
refers to a non-existent orchestration. This facilitates a clean
40+
implementation of the Singleton pattern
41+
42+
Returns
43+
-------
44+
bool
45+
True if self._created_time is not None. False otherwise.
46+
"""
47+
return self._created_time is not None
48+
3449
@classmethod
3550
def from_json(cls, json_obj: Any):
3651
"""Convert the value passed into a new instance of the class.

azure/durable_functions/models/utils/http_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ async def get_async_request(url: str) -> [int, Any]:
4444
"""
4545
async with aiohttp.ClientSession() as session:
4646
async with session.get(url) as response:
47-
data = await response.json()
47+
data = await response.json(content_type=None)
48+
if data is None:
49+
data = ""
4850
return [response.status, data]
4951

5052

0 commit comments

Comments
 (0)