Skip to content

Add debugging helper to pretty print history #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 11, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions azure/durable_functions/models/DurableOrchestrationContext.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -459,3 +461,15 @@ 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):
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))