Skip to content

Commit

Permalink
ENH: Make output values and manifest optional in result message
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Update all your services to this version.
  • Loading branch information
cortadocodes committed Nov 15, 2023
1 parent 8118bbb commit 1ee344c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions octue/cloud/pub_sub/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ def _handle_result(self, message):
"""
logger.info("%r received an answer to question %r.", self.receiving_service, self.question_uuid)

if message["output_manifest"] is None:
output_manifest = None
else:
if message.get("output_manifest"):
output_manifest = Manifest.deserialise(message["output_manifest"])
else:
output_manifest = None

return {"output_values": message["output_values"], "output_manifest": output_manifest}
return {"output_values": message.get("output_values"), "output_manifest": output_manifest}
17 changes: 8 additions & 9 deletions octue/cloud/pub_sub/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,16 @@ def answer(self, question, heartbeat_interval=120, timeout=30):
allow_save_diagnostics_data_on_crash=allow_save_diagnostics_data_on_crash,
)

if analysis.output_manifest is None:
serialised_output_manifest = None
else:
serialised_output_manifest = analysis.output_manifest.to_primitive()
result = {"type": "result"}

if analysis.output_values is not None:
result["output_values"] = analysis.output_values

if analysis.output_manifest is not None:
result["output_manifest"] = analysis.output_manifest.to_primitive()

self._send_message(
{
"type": "result",
"output_values": analysis.output_values,
"output_manifest": serialised_output_manifest,
},
message=result,
topic=topic,
attributes={"question_uuid": question_uuid, "is_question": False},
timeout=timeout,
Expand Down
2 changes: 1 addition & 1 deletion tests/cloud/pub_sub/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def test_child_messages_can_be_recorded_by_parent(self):

self.assertEqual(
parent.received_messages[4],
{"type": "result", "output_values": "Hello! It worked!", "output_manifest": None},
{"type": "result", "output_values": "Hello! It worked!"},
)

def test_child_exception_message_can_be_recorded_by_parent(self):
Expand Down

0 comments on commit 1ee344c

Please sign in to comment.