-
Notifications
You must be signed in to change notification settings - Fork 2
Inject result_type on publish to SNS, not on read
#33
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| from jinja2 import TemplateError | ||
|
|
||
| from lambdacron.lambda_task import build_result_message_payload | ||
| from lambdacron.notifications.base import ( | ||
| FileTemplateProvider, | ||
| RenderedTemplateNotificationHandler, | ||
|
|
@@ -46,8 +47,7 @@ def build_parser() -> argparse.ArgumentParser: | |
| class RenderNotificationHandler(RenderedTemplateNotificationHandler): | ||
| def __init__(self, *, template_path: Path, stream: TextIO | None = None) -> None: | ||
| super().__init__( | ||
| template_providers={"body": FileTemplateProvider(template_path)}, | ||
| include_result_type=True, | ||
| template_providers={"body": FileTemplateProvider(template_path)} | ||
| ) | ||
| self.stream = stream or sys.stdout | ||
|
|
||
|
|
@@ -95,11 +95,15 @@ def extract_result_payload(payload_json: str, *, result_type: str) -> str: | |
| if not isinstance(payload, dict): | ||
| raise ValueError("Task output must be a JSON object keyed by result type") | ||
| selected = payload.get(result_type) | ||
| if not isinstance(selected, dict): | ||
| if not isinstance(selected, Mapping): | ||
| raise ValueError( | ||
| f"Result payload for type '{result_type}' must be a JSON object" | ||
| f"Result payload for type '{result_type}' must be a JSON object, " | ||
| f"got {type(selected).__name__}" | ||
| ) | ||
| return json.dumps(selected) | ||
| payload_for_publish = build_result_message_payload( | ||
| result_type=result_type, message=selected | ||
| ) | ||
| return json.dumps(payload_for_publish) | ||
|
Comment on lines
95
to
+106
|
||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring every incoming payload to include a non-empty string
result_typeis a behavior change that will cause any in-flight/older SQS messages (published before this change) to fail parsing and be retried indefinitely as batchItemFailures. Consider a backward-compatible transition: ifpayload.result_typeis missing/empty butmessageAttributes.result_typeis present, inject it (and optionally log a warning / plan a deprecation), while still rejecting mismatches when both are present.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not worried about backward compatibility here.