Skip to content

DX Improvements #140

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 5 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 6 additions & 13 deletions src/resonate/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ def decode(self, data: str) -> str:
return base64.b64decode(data).decode()


# Helper method to make Errors serializable
def _default(data: Any) -> Any: # noqa: ANN401
if isinstance(data, Exception):
return {
"__type": _classname(data),
"attributes": data.__dict__,
}

return data


# Helper method to deserialize errors
def _object_hook(data: dict[str, Any]) -> Any: # noqa: ANN401
if "__type" in data:
error_cls = _import_class_from_qualified_name(data["__type"])
Expand All @@ -52,7 +40,12 @@ def _object_hook(data: dict[str, Any]) -> Any: # noqa: ANN401
@final
class JsonEncoder(IEncoder[Any, str]):
def encode(self, data: Any) -> str: # noqa: ANN401
return json.dumps(data, default=_default)
if isinstance(data, Exception):
data = {
"__type": _classname(data),
"attributes": data.__dict__,
}
return json.dumps(data)

def decode(self, data: str) -> Any: # noqa: ANN401
return json.loads(data, object_hook=_object_hook)
Expand Down
6 changes: 6 additions & 0 deletions src/resonate/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ def _handle_complete(
if isinstance(record, str):
record = self._records[record]
if record.should_retry(value):
error = value.err() # Get the exception instance.
logger.warning(
"Error processing record %s: Retrying execution.",
record.id,
exc_info=error, # This includes the traceback.
)
record.increate_attempt()
self._delay_queue.enqueue(Invoke(record.id), record.next_retry_delay())
return []
Expand Down