Skip to content

Commit 450a280

Browse files
authored
MRG: Merge pull request #650 from octue/upgrade-twined
Use updated `twined`
2 parents 55a6394 + 5db9609 commit 450a280

File tree

14 files changed

+908
-755
lines changed

14 files changed

+908
-755
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- id: isort
1919

2020
- repo: https://github.com/psf/black
21-
rev: 22.6.0
21+
rev: 24.4.2
2222
hooks:
2323
- id: black
2424
args: ["--line-length", "120"]

docs/source/inter_service_compatibility.rst

+77-73
Large diffs are not rendered by default.

octue/cloud/deployment/google/answer_pub_sub_question.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from octue.cloud.events.counter import EventCounter
34
from octue.cloud.pub_sub.service import Service
45
from octue.cloud.service_id import create_sruid, get_sruid_parts
56
from octue.configuration import load_service_and_app_configuration
@@ -32,6 +33,7 @@ def answer_question(question, project_name):
3233

3334
service = Service(service_id=service_sruid, backend=GCPPubSubBackend(project_name=project_name))
3435
question_uuid = get_nested_attribute(question, "attributes.question_uuid")
36+
order = EventCounter()
3537

3638
try:
3739
runner = Runner.from_configuration(
@@ -42,9 +44,9 @@ def answer_question(question, project_name):
4244
)
4345

4446
service.run_function = runner.run
45-
service.answer(question)
47+
service.answer(question, order)
4648
logger.info("Analysis successfully run and response sent for question %r.", question_uuid)
4749

4850
except BaseException as error: # noqa
49-
service.send_exception(question_uuid=question_uuid, originator="UNKNOWN")
51+
service.send_exception(question_uuid=question_uuid, originator="UNKNOWN", order=order)
5052
logger.exception(error)

octue/cloud/deployment/google/cloud_run/flask_app.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def index():
2222
return _log_bad_request_and_return_400_response("No Pub/Sub message received.")
2323

2424
if not isinstance(envelope, dict) or "message" not in envelope:
25-
return _log_bad_request_and_return_400_response("Invalid Pub/Sub message format.")
25+
return _log_bad_request_and_return_400_response(f"Invalid Pub/Sub message format - received {envelope!r}.")
2626

2727
question = envelope["message"]
2828

2929
if "data" not in question or "attributes" not in question or "question_uuid" not in question["attributes"]:
30-
return _log_bad_request_and_return_400_response("Invalid Pub/Sub message format.")
30+
return _log_bad_request_and_return_400_response(f"Invalid Pub/Sub message format - received {envelope!r}.")
3131

3232
question_uuid = question["attributes"]["question_uuid"]
3333

octue/cloud/pub_sub/bigquery.py

-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
31
from google.cloud.bigquery import Client, QueryJobConfig, ScalarQueryParameter
42

53
from octue.cloud.events.validation import VALID_EVENT_KINDS
@@ -76,14 +74,7 @@ def get_events(table_id, sender, question_uuid, kind=None, include_backend_metad
7674
)
7775

7876
df = result.to_dataframe()
79-
80-
# Convert JSON strings to python primitives.
81-
df["event"] = df["event"].map(json.loads)
8277
df["event"].apply(_deserialise_manifest_if_present)
83-
df["other_attributes"] = df["other_attributes"].map(json.loads)
84-
85-
if "backend_metadata" in df:
86-
df["backend_metadata"] = df["backend_metadata"].map(json.loads)
8778

8879
events = df.to_dict(orient="records")
8980
return _unflatten_events(events)

octue/cloud/pub_sub/service.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,19 @@ def serve(self, timeout=None, delete_topic_and_subscription_on_exit=False, allow
203203

204204
return future, subscriber
205205

206-
def answer(self, question, heartbeat_interval=120, timeout=30):
206+
def answer(self, question, order=None, heartbeat_interval=120, timeout=30):
207207
"""Answer a question from a parent - i.e. run the child's app on the given data and return the output values.
208208
Answers conform to the output values and output manifest schemas specified in the child's Twine file.
209209
210210
:param dict|google.cloud.pubsub_v1.subscriber.message.Message question:
211+
:param octue.cloud.events.counter.EventCounter|None order: an event counter keeping track of the order of emitted events
211212
:param int|float heartbeat_interval: the time interval, in seconds, at which to send heartbeats
212213
:param float|None timeout: time in seconds to keep retrying sending of the answer once it has been calculated
213214
:raise Exception: if any exception arises during running analysis and sending its results
214215
:return None:
215216
"""
217+
order = order or EventCounter()
218+
216219
try:
217220
(
218221
question,
@@ -226,7 +229,6 @@ def answer(self, question, heartbeat_interval=120, timeout=30):
226229
return
227230

228231
heartbeater = None
229-
order = EventCounter()
230232

231233
try:
232234
self._send_delivery_acknowledgment(question_uuid, originator, order)

octue/metadata/recorded_questions.jsonl

+2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@
3131
{"parent_sdk_version": "0.51.0", "question": {"data": "{\"kind\": \"question\", \"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"3bf3b178-3cf1-49aa-a1d9-89cd8ec05b1a\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmppu85nw5c\"}}}", "attributes": {"question_uuid": "6f7f6e1c-7632-4b4d-b91d-6f58dcb43c40", "sender_type": "PARENT", "forward_logs": "1", "save_diagnostics": "SAVE_DIAGNOSTICS_ON_CRASH", "version": "0.51.0", "message_number": "0"}}}
3232
{"parent_sdk_version": "0.52.0", "question": {"data": "{\"kind\": \"question\", \"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"6be875b3-33d8-4b00-b7ea-553f8f69bce5\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmphypwu9uh\"}}}", "attributes": {"question_uuid": "cd0a78be-fda2-4730-bdba-ba6b04e4787f", "sender_type": "PARENT", "forward_logs": "1", "save_diagnostics": "SAVE_DIAGNOSTICS_ON_CRASH", "version": "0.52.0", "message_number": "0"}}}
3333
{"parent_sdk_version": "0.52.1", "question": {"data": "{\"kind\": \"question\", \"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"6be875b3-33d8-4b00-b7ea-553f8f69bce5\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmphypwu9uh\"}}}", "attributes": {"question_uuid": "cd0a78be-fda2-4730-bdba-ba6b04e4787f", "sender_type": "PARENT", "forward_logs": "1", "save_diagnostics": "SAVE_DIAGNOSTICS_ON_CRASH", "version": "0.52.1", "message_number": "0"}}}
34+
{"parent_sdk_version": "0.52.2", "question": {"data": "{\"kind\": \"question\", \"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"6be875b3-33d8-4b00-b7ea-553f8f69bce5\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmphypwu9uh\"}}}", "attributes": {"question_uuid": "cd0a78be-fda2-4730-bdba-ba6b04e4787f", "sender_type": "PARENT", "forward_logs": "1", "save_diagnostics": "SAVE_DIAGNOSTICS_ON_CRASH", "version": "0.52.2", "message_number": "0"}}}
3435
{"parent_sdk_version": "0.53.0", "question": {"data": "{\"kind\": \"question\", \"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"6be875b3-33d8-4b00-b7ea-553f8f69bce5\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmphypwu9uh\"}}}", "attributes": {"datetime": "2024-04-11T10:46:48.236064", "uuid": "a9de11b1-e88f-43fa-b3a4-40a590c3443f", "question_uuid": "cd0a78be-fda2-4730-bdba-ba6b04e4787f", "forward_logs": "1", "save_diagnostics": "SAVE_DIAGNOSTICS_ON_CRASH", "originator": "octue/test-service:0.1.0", "sender": "octue/test-service:0.1.0", "sender_type": "PARENT", "sender_sdk_version": "0.53.0", "recipient": "octue/another-service:1.0.12", "order": "0"}}}
3536
{"parent_sdk_version": "0.54.0", "question": {"data": "{\"kind\": \"question\", \"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"6be875b3-33d8-4b00-b7ea-553f8f69bce5\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmphypwu9uh\"}}}", "attributes": {"datetime": "2024-04-11T10:46:48.236064", "uuid": "a9de11b1-e88f-43fa-b3a4-40a590c3443f", "question_uuid": "cd0a78be-fda2-4730-bdba-ba6b04e4787f", "forward_logs": "1", "save_diagnostics": "SAVE_DIAGNOSTICS_ON_CRASH", "originator": "octue/test-service:0.1.0", "sender": "octue/test-service:0.1.0", "sender_type": "PARENT", "sender_sdk_version": "0.54.0", "recipient": "octue/another-service:1.0.12", "order": "0"}}}
37+
{"parent_sdk_version": "0.55.0", "question": {"data": "{\"kind\": \"question\", \"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"6be875b3-33d8-4b00-b7ea-553f8f69bce5\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmphypwu9uh\"}}}", "attributes": {"datetime": "2024-04-11T10:46:48.236064", "uuid": "a9de11b1-e88f-43fa-b3a4-40a590c3443f", "question_uuid": "cd0a78be-fda2-4730-bdba-ba6b04e4787f", "forward_logs": "1", "save_diagnostics": "SAVE_DIAGNOSTICS_ON_CRASH", "originator": "octue/test-service:0.1.0", "sender": "octue/test-service:0.1.0", "sender_type": "PARENT", "sender_sdk_version": "0.55.0", "recipient": "octue/another-service:1.0.12", "order": "0"}}}

0 commit comments

Comments
 (0)