Skip to content

Commit da6faa5

Browse files
committed
REF: Factor out default maximum heartbeat interval
1 parent ca09b78 commit da6faa5

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

octue/cloud/pub_sub/events.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from octue.cloud.events.attributes import ResponseAttributes
1111
from octue.cloud.events.handler import AbstractEventHandler
1212
from octue.cloud.events.validation import SERVICE_COMMUNICATION_SCHEMA
13+
from octue.definitions import DEFAULT_MAXIMUM_HEARTBEAT_INTERVAL
1314
from octue.utils.decoders import OctueJSONDecoder
1415
from octue.utils.objects import get_nested_attribute
1516
from octue.utils.threads import RepeatingTimer
@@ -110,7 +111,7 @@ def _time_since_last_heartbeat(self):
110111

111112
return datetime.now() - self._last_heartbeat
112113

113-
def handle_events(self, timeout=60, maximum_heartbeat_interval=360):
114+
def handle_events(self, timeout=60, maximum_heartbeat_interval=DEFAULT_MAXIMUM_HEARTBEAT_INTERVAL):
114115
"""Pull events from the subscription and handle them in the order they were sent until a "result" event is
115116
handled, then return the handled result.
116117

octue/cloud/pub_sub/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
validate_sruid,
2525
)
2626
from octue.compatibility import warn_if_incompatible
27-
from octue.definitions import LOCAL_SDK_VERSION
27+
from octue.definitions import DEFAULT_MAXIMUM_HEARTBEAT_INTERVAL, LOCAL_SDK_VERSION
2828
import octue.exceptions
2929
from octue.utils.dictionaries import make_minimal_dictionary
3030
from octue.utils.encoders import OctueJSONEncoder
@@ -383,7 +383,7 @@ def wait_for_answer(
383383
handle_monitor_message=None,
384384
record_events=True,
385385
timeout=60,
386-
maximum_heartbeat_interval=360,
386+
maximum_heartbeat_interval=DEFAULT_MAXIMUM_HEARTBEAT_INTERVAL,
387387
):
388388
"""Wait for an answer to a question on the given subscription, deleting the subscription and its topic once
389389
the answer is received.

octue/definitions.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020

2121
GOOGLE_COMPUTE_PROVIDERS = {"GOOGLE_CLOUD_FUNCTION"}
2222
LOCAL_SDK_VERSION = importlib.metadata.version("octue")
23+
DEFAULT_MAXIMUM_HEARTBEAT_INTERVAL = 360

octue/resources/child.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55

66
from octue.cloud.pub_sub.service import Service
7+
from octue.definitions import DEFAULT_MAXIMUM_HEARTBEAT_INTERVAL
78
from octue.resources import service_backends
89

910
logger = logging.getLogger(__name__)
@@ -76,7 +77,7 @@ def ask(
7677
prevent_retries_when=None,
7778
log_errors=True,
7879
timeout=86400,
79-
maximum_heartbeat_interval=360,
80+
maximum_heartbeat_interval=DEFAULT_MAXIMUM_HEARTBEAT_INTERVAL,
8081
):
8182
"""Ask the child either:
8283
- A synchronous (ask-and-wait) question and wait for it to return an output. Questions are synchronous if

0 commit comments

Comments
 (0)