Skip to content

Commit da425a0

Browse files
authored
Add debugging helper to pretty print history (#287)
1 parent c9f2464 commit da425a0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

azure/durable_functions/models/DurableOrchestrationContext.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
22
import datetime
3+
import inspect
34
from typing import List, Any, Dict, Optional
45
from uuid import UUID, uuid5, NAMESPACE_URL
6+
from datetime import timezone
57

68
from .RetryOptions import RetryOptions
79
from .TaskSet import TaskSet
@@ -459,3 +461,15 @@ def new_guid(self) -> UUID:
459461
self._new_uuid_counter += 1
460462
guid = uuid5(NAMESPACE_URL, guid_name)
461463
return guid
464+
465+
def _pretty_print_history(self) -> str:
466+
"""Get a pretty-printed version of the orchestration's internal history."""
467+
def history_to_string(event):
468+
json_dict = {}
469+
for key, val in inspect.getmembers(event):
470+
if not key.startswith('_') and not inspect.ismethod(val):
471+
if isinstance(val, datetime.date):
472+
val = val.replace(tzinfo=timezone.utc).timetuple()
473+
json_dict[key] = val
474+
return json.dumps(json_dict)
475+
return str(list(map(history_to_string, self._histories)))

0 commit comments

Comments
 (0)