From 7603e5d450cbecaa789ad6a862dd207de6ff10fe Mon Sep 17 00:00:00 2001 From: David Justo Date: Tue, 11 May 2021 16:14:35 -0700 Subject: [PATCH 1/4] add pretty print history method, for debugging help --- .../models/DurableOrchestrationContext.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/azure/durable_functions/models/DurableOrchestrationContext.py b/azure/durable_functions/models/DurableOrchestrationContext.py index b25683da..64a560f4 100644 --- a/azure/durable_functions/models/DurableOrchestrationContext.py +++ b/azure/durable_functions/models/DurableOrchestrationContext.py @@ -1,7 +1,9 @@ import json import datetime +import inspect from typing import List, Any, Dict, Optional from uuid import UUID, uuid5, NAMESPACE_URL +from datetime import timezone from .RetryOptions import RetryOptions from .TaskSet import TaskSet @@ -459,3 +461,14 @@ def new_guid(self) -> UUID: self._new_uuid_counter += 1 guid = uuid5(NAMESPACE_URL, guid_name) return guid + + def _pretty_print_history(self) -> str: + def history_to_string(event): + json_dict = {} + for key, val in inspect.getmembers(event): + if not key.startswith('_') and not inspect.ismethod(val): + if isinstance(val, datetime.date): + val = val.replace(tzinfo=timezone.utc).timetuple() + json_dict[key] = val + return json.dumps(json_dict) + return list(map(history_to_string, self._histories)) \ No newline at end of file From 6d682c3118c5b6b6219c8180c932d2f317e3fa1d Mon Sep 17 00:00:00 2001 From: David Justo Date: Tue, 1 Jun 2021 15:55:32 -0700 Subject: [PATCH 2/4] lint --- .../durable_functions/models/DurableOrchestrationContext.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/azure/durable_functions/models/DurableOrchestrationContext.py b/azure/durable_functions/models/DurableOrchestrationContext.py index 64a560f4..ce634659 100644 --- a/azure/durable_functions/models/DurableOrchestrationContext.py +++ b/azure/durable_functions/models/DurableOrchestrationContext.py @@ -461,8 +461,9 @@ def new_guid(self) -> UUID: self._new_uuid_counter += 1 guid = uuid5(NAMESPACE_URL, guid_name) return guid - + def _pretty_print_history(self) -> str: + """Get a pretty-printed version of the orchestration's internal history.""" def history_to_string(event): json_dict = {} for key, val in inspect.getmembers(event): @@ -471,4 +472,4 @@ def history_to_string(event): val = val.replace(tzinfo=timezone.utc).timetuple() json_dict[key] = val return json.dumps(json_dict) - return list(map(history_to_string, self._histories)) \ No newline at end of file + return list(map(history_to_string, self._histories)) From d768222c3137cb4293c534da542a29c74166787f Mon Sep 17 00:00:00 2001 From: David Justo Date: Thu, 3 Jun 2021 08:58:47 -0700 Subject: [PATCH 3/4] fix type annotation --- azure/durable_functions/models/DurableOrchestrationContext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure/durable_functions/models/DurableOrchestrationContext.py b/azure/durable_functions/models/DurableOrchestrationContext.py index ce634659..84d155ce 100644 --- a/azure/durable_functions/models/DurableOrchestrationContext.py +++ b/azure/durable_functions/models/DurableOrchestrationContext.py @@ -462,7 +462,7 @@ def new_guid(self) -> UUID: guid = uuid5(NAMESPACE_URL, guid_name) return guid - def _pretty_print_history(self) -> str: + def _pretty_print_history(self) -> List[str]: """Get a pretty-printed version of the orchestration's internal history.""" def history_to_string(event): json_dict = {} From 11e31a61be7d90e4b1b63a043efece82ce3166be Mon Sep 17 00:00:00 2001 From: David Justo Date: Thu, 3 Jun 2021 09:00:01 -0700 Subject: [PATCH 4/4] return str --- azure/durable_functions/models/DurableOrchestrationContext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure/durable_functions/models/DurableOrchestrationContext.py b/azure/durable_functions/models/DurableOrchestrationContext.py index 84d155ce..784f1247 100644 --- a/azure/durable_functions/models/DurableOrchestrationContext.py +++ b/azure/durable_functions/models/DurableOrchestrationContext.py @@ -462,7 +462,7 @@ def new_guid(self) -> UUID: guid = uuid5(NAMESPACE_URL, guid_name) return guid - def _pretty_print_history(self) -> List[str]: + def _pretty_print_history(self) -> str: """Get a pretty-printed version of the orchestration's internal history.""" def history_to_string(event): json_dict = {} @@ -472,4 +472,4 @@ def history_to_string(event): val = val.replace(tzinfo=timezone.utc).timetuple() json_dict[key] = val return json.dumps(json_dict) - return list(map(history_to_string, self._histories)) + return str(list(map(history_to_string, self._histories)))