Skip to content

Commit 7811eee

Browse files
committed
FIX: Add missing parent_question_uuid parameters
1 parent 5a669f4 commit 7811eee

File tree

4 files changed

+79
-37
lines changed

4 files changed

+79
-37
lines changed

octue/cloud/emulators/child.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def ask(
106106
handle_monitor_message=None,
107107
record_events=True,
108108
question_uuid=None,
109+
parent_question_uuid=None,
109110
push_endpoint=None,
110111
asynchronous=False,
111112
timeout=86400,
@@ -121,6 +122,7 @@ def ask(
121122
:param callable|None handle_monitor_message: a function to handle monitor messages (e.g. send them to an endpoint for plotting or displaying) - this function should take a single JSON-compatible python primitive as an argument (note that this could be an array or object)
122123
:param bool record_events: if `True`, record events received from the child in the `received_events` property
123124
:param str|None question_uuid: the UUID to use for the question if a specific one is needed; a UUID is generated if not
125+
:param str|None parent_question_uuid:
124126
:param str|None push_endpoint: if answers to the question should be pushed to an endpoint, provide its URL here (the returned subscription will be a push subscription); if not, leave this as `None`
125127
:param bool asynchronous: if `True`, don't create an answer subscription
126128
:param float timeout: time in seconds to wait for an answer before raising a timeout error
@@ -137,6 +139,7 @@ def ask(
137139
subscribe_to_logs=subscribe_to_logs,
138140
allow_local_files=allow_local_files,
139141
question_uuid=question_uuid,
142+
parent_question_uuid=parent_question_uuid,
140143
push_endpoint=push_endpoint,
141144
asynchronous=asynchronous,
142145
)

octue/cloud/pub_sub/service.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def answer(self, question, order=None, heartbeat_interval=120, timeout=30):
269269
handle_monitor_message=functools.partial(
270270
self._send_monitor_message,
271271
question_uuid=question_uuid,
272+
parent_question_uuid=parent_question_uuid,
272273
originator=originator,
273274
order=order,
274275
),
@@ -474,7 +475,17 @@ def _emit_event(
474475
timeout=30,
475476
):
476477
"""Emit a JSON-serialised event as a Pub/Sub message to the services topic with optional message attributes,
477-
incrementing the `order` argument by one. This method is thread-safe.
478+
incrementing the `order` argument by one. This method is thread-safe. Extra attributes can be added to an event
479+
via the `attributes` argument but the following attributes are always included:
480+
- `uuid` (event UUID)
481+
- `question_uuid`
482+
- `parent_question_uuid`
483+
- `originator`
484+
- `sender`
485+
- `sender_sdk_version`
486+
- `recipient`
487+
- `order`
488+
- `datetime`
478489
479490
:param dict event: JSON-serialisable data to emit as an event
480491
:param str question_uuid:

tests/cloud/pub_sub/test_events.py

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,27 @@ def test_in_order_messages_are_handled_in_order(self):
6464
messages = [
6565
{
6666
"event": {"kind": "test", "order": 0},
67-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
67+
"attributes": {"sender_type": "CHILD"},
6868
},
6969
{
7070
"event": {"kind": "test", "order": 1},
71-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
71+
"attributes": {"sender_type": "CHILD"},
7272
},
7373
{
7474
"event": {"kind": "test", "order": 2},
75-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
75+
"attributes": {"sender_type": "CHILD"},
7676
},
7777
{
7878
"event": {"kind": "finish-test", "order": 3},
79-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
79+
"attributes": {"sender_type": "CHILD"},
8080
},
8181
]
8282

8383
for message in messages:
8484
child._emit_event(
8585
event=message["event"],
86+
question_uuid=self.question_uuid,
87+
parent_question_uuid=None,
8688
attributes=message["attributes"],
8789
originator=self.parent.id,
8890
recipient=self.parent.id,
@@ -116,25 +118,27 @@ def test_out_of_order_messages_are_handled_in_order(self):
116118
messages = [
117119
{
118120
"event": {"kind": "test", "order": 1},
119-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
121+
"attributes": {"sender_type": "CHILD"},
120122
},
121123
{
122124
"event": {"kind": "test", "order": 2},
123-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
125+
"attributes": {"sender_type": "CHILD"},
124126
},
125127
{
126128
"event": {"kind": "test", "order": 0},
127-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
129+
"attributes": {"sender_type": "CHILD"},
128130
},
129131
{
130132
"event": {"kind": "finish-test", "order": 3},
131-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
133+
"attributes": {"sender_type": "CHILD"},
132134
},
133135
]
134136

135137
for message in messages:
136138
child._emit_event(
137139
event=message["event"],
140+
question_uuid=self.question_uuid,
141+
parent_question_uuid=None,
138142
attributes=message["attributes"],
139143
originator=self.parent.id,
140144
recipient=self.parent.id,
@@ -171,25 +175,27 @@ def test_out_of_order_messages_with_end_message_first_are_handled_in_order(self)
171175
messages = [
172176
{
173177
"event": {"kind": "finish-test", "order": 3},
174-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
178+
"attributes": {"sender_type": "CHILD"},
175179
},
176180
{
177181
"event": {"kind": "test", "order": 1},
178-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
182+
"attributes": {"sender_type": "CHILD"},
179183
},
180184
{
181185
"event": {"kind": "test", "order": 2},
182-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
186+
"attributes": {"sender_type": "CHILD"},
183187
},
184188
{
185189
"event": {"kind": "test", "order": 0},
186-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
190+
"attributes": {"sender_type": "CHILD"},
187191
},
188192
]
189193

190194
for message in messages:
191195
child._emit_event(
192196
event=message["event"],
197+
question_uuid=self.question_uuid,
198+
parent_question_uuid=None,
193199
attributes=message["attributes"],
194200
originator=self.parent.id,
195201
recipient=self.parent.id,
@@ -224,21 +230,23 @@ def test_no_timeout(self):
224230
messages = [
225231
{
226232
"event": {"kind": "test", "order": 0},
227-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
233+
"attributes": {"sender_type": "CHILD"},
228234
},
229235
{
230236
"event": {"kind": "test", "order": 1},
231-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
237+
"attributes": {"sender_type": "CHILD"},
232238
},
233239
{
234240
"event": {"kind": "finish-test", "order": 2},
235-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
241+
"attributes": {"sender_type": "CHILD"},
236242
},
237243
]
238244

239245
for message in messages:
240246
child._emit_event(
241247
event=message["event"],
248+
question_uuid=self.question_uuid,
249+
parent_question_uuid=None,
242250
attributes=message["attributes"],
243251
originator=self.parent.id,
244252
recipient=self.parent.id,
@@ -265,17 +273,19 @@ def test_delivery_acknowledgement(self):
265273
"datetime": datetime.datetime.utcnow().isoformat(),
266274
"order": 0,
267275
},
268-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
276+
"attributes": {"sender_type": "CHILD"},
269277
},
270278
{
271279
"event": {"kind": "result", "order": 1},
272-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
280+
"attributes": {"sender_type": "CHILD"},
273281
},
274282
]
275283

276284
for message in messages:
277285
child._emit_event(
278286
event=message["event"],
287+
question_uuid=self.question_uuid,
288+
parent_question_uuid=None,
279289
attributes=message["attributes"],
280290
originator=self.parent.id,
281291
recipient=self.parent.id,
@@ -318,17 +328,19 @@ def test_error_not_raised_if_heartbeat_has_been_received_in_maximum_allowed_inte
318328
"datetime": datetime.datetime.utcnow().isoformat(),
319329
"order": 0,
320330
},
321-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
331+
"attributes": {"sender_type": "CHILD"},
322332
},
323333
{
324334
"event": {"kind": "result", "order": 1},
325-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
335+
"attributes": {"sender_type": "CHILD"},
326336
},
327337
]
328338

329339
for message in messages:
330340
child._emit_event(
331341
event=message["event"],
342+
question_uuid=self.question_uuid,
343+
parent_question_uuid=None,
332344
attributes=message["attributes"],
333345
originator=self.parent.id,
334346
recipient=self.parent.id,
@@ -376,25 +388,27 @@ def test_missing_messages_at_start_can_be_skipped(self):
376388
messages = [
377389
{
378390
"event": {"kind": "test", "order": 2},
379-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
391+
"attributes": {"sender_type": "CHILD"},
380392
},
381393
{
382394
"event": {"kind": "test", "order": 3},
383-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
395+
"attributes": {"sender_type": "CHILD"},
384396
},
385397
{
386398
"event": {"kind": "test", "order": 4},
387-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
399+
"attributes": {"sender_type": "CHILD"},
388400
},
389401
{
390402
"event": {"kind": "finish-test", "order": 5},
391-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
403+
"attributes": {"sender_type": "CHILD"},
392404
},
393405
]
394406

395407
for message in messages:
396408
child._emit_event(
397409
event=message["event"],
410+
question_uuid=self.question_uuid,
411+
parent_question_uuid=None,
398412
attributes=message["attributes"],
399413
originator=self.parent.id,
400414
recipient=self.parent.id,
@@ -437,21 +451,23 @@ def test_missing_messages_in_middle_can_skipped(self):
437451
messages = [
438452
{
439453
"event": {"kind": "test", "order": 0},
440-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
454+
"attributes": {"sender_type": "CHILD"},
441455
},
442456
{
443457
"event": {"kind": "test", "order": 1},
444-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
458+
"attributes": {"sender_type": "CHILD"},
445459
},
446460
{
447461
"event": {"kind": "test", "order": 2},
448-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
462+
"attributes": {"sender_type": "CHILD"},
449463
},
450464
]
451465

452466
for message in messages:
453467
child._emit_event(
454468
event=message["event"],
469+
question_uuid=self.question_uuid,
470+
parent_question_uuid=None,
455471
attributes=message["attributes"],
456472
originator=self.parent.id,
457473
recipient=self.parent.id,
@@ -461,7 +477,9 @@ def test_missing_messages_in_middle_can_skipped(self):
461477
# Send a final message.
462478
child._emit_event(
463479
event={"kind": "finish-test", "order": 5},
464-
attributes={"question_uuid": self.question_uuid, "sender_type": "CHILD"},
480+
question_uuid=self.question_uuid,
481+
parent_question_uuid=None,
482+
attributes={"sender_type": "CHILD"},
465483
originator=self.parent.id,
466484
recipient=self.parent.id,
467485
# Simulate missing messages.
@@ -504,21 +522,23 @@ def test_multiple_blocks_of_missing_messages_in_middle_can_skipped(self):
504522
messages = [
505523
{
506524
"event": {"kind": "test", "order": 0},
507-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
525+
"attributes": {"sender_type": "CHILD"},
508526
},
509527
{
510528
"event": {"kind": "test", "order": 1},
511-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
529+
"attributes": {"sender_type": "CHILD"},
512530
},
513531
{
514532
"event": {"kind": "test", "order": 2},
515-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
533+
"attributes": {"sender_type": "CHILD"},
516534
},
517535
]
518536

519537
for message in messages:
520538
child._emit_event(
521539
event=message["event"],
540+
question_uuid=self.question_uuid,
541+
parent_question_uuid=None,
522542
attributes=message["attributes"],
523543
originator=self.parent.id,
524544
recipient=self.parent.id,
@@ -528,7 +548,9 @@ def test_multiple_blocks_of_missing_messages_in_middle_can_skipped(self):
528548
# Send another message.
529549
child._emit_event(
530550
event={"kind": "test", "order": 5},
531-
attributes={"order": 5, "question_uuid": self.question_uuid, "sender_type": "CHILD"},
551+
question_uuid=self.question_uuid,
552+
parent_question_uuid=None,
553+
attributes={"order": 5, "sender_type": "CHILD"},
532554
originator=self.parent.id,
533555
recipient=self.parent.id,
534556
# Simulate missing messages.
@@ -539,25 +561,27 @@ def test_multiple_blocks_of_missing_messages_in_middle_can_skipped(self):
539561
messages = [
540562
{
541563
"event": {"kind": "test", "order": 20},
542-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
564+
"attributes": {"sender_type": "CHILD"},
543565
},
544566
{
545567
"event": {"kind": "test", "order": 21},
546-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
568+
"attributes": {"sender_type": "CHILD"},
547569
},
548570
{
549571
"event": {"kind": "test", "order": 22},
550-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
572+
"attributes": {"sender_type": "CHILD"},
551573
},
552574
{
553575
"event": {"kind": "finish-test", "order": 23},
554-
"attributes": {"question_uuid": self.question_uuid, "sender_type": "CHILD"},
576+
"attributes": {"sender_type": "CHILD"},
555577
},
556578
]
557579

558580
for message in messages:
559581
child._emit_event(
560582
event=message["event"],
583+
question_uuid=self.question_uuid,
584+
parent_question_uuid=None,
561585
attributes=message["attributes"],
562586
originator=self.parent.id,
563587
recipient=self.parent.id,
@@ -610,7 +634,9 @@ def test_all_messages_missing_apart_from_result(self):
610634
# Send the result message.
611635
child._emit_event(
612636
event={"kind": "finish-test", "order": 1000},
613-
attributes={"question_uuid": self.question_uuid, "sender_type": "CHILD"},
637+
question_uuid=self.question_uuid,
638+
parent_question_uuid=None,
639+
attributes={"sender_type": "CHILD"},
614640
originator=self.parent.id,
615641
recipient=self.parent.id,
616642
# Simulate missing messages.

tests/cloud/pub_sub/test_logging.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_emit(self):
4444
GoogleCloudPubSubHandler(
4545
event_emitter=service._emit_event,
4646
question_uuid=question_uuid,
47+
parent_question_uuid=None,
4748
originator="another/service:1.0.0",
4849
recipient="another/service:1.0.0",
4950
order=EventCounter(),
@@ -74,6 +75,7 @@ def test_emit_with_non_json_serialisable_args(self):
7475
GoogleCloudPubSubHandler(
7576
event_emitter=service._emit_event,
7677
question_uuid="question-uuid",
78+
parent_question_uuid=None,
7779
originator="another/service:1.0.0",
7880
recipient="another/service:1.0.0",
7981
order=EventCounter(),

0 commit comments

Comments
 (0)