@@ -73,8 +73,8 @@ def set_default(runtime: Runtime, *, error_if_already_set: bool = True) -> None:
7373 def __init__ (
7474 self ,
7575 * ,
76- telemetry : Optional [ TelemetryConfig ] = None ,
77- runtime_options : Optional ["RuntimeOptions" ] = None ,
76+ telemetry : TelemetryConfig ,
77+ worker_heartbeat_interval : Optional [timedelta ] = timedelta ( seconds = 30 ) ,
7878 ) -> None :
7979 """Create a runtime with the provided configuration.
8080
@@ -83,25 +83,29 @@ def __init__(
8383 Args:
8484 telemetry: Telemetry configuration when not supplying
8585 ``runtime_options``.
86- runtime_options: Full runtime configuration including telemetry and
87- worker heartbeating options .
86+ worker_heartbeat_interval: Interval for worker heartbeats. ``None``
87+ disables heartbeating.
8888
8989 Raises:
90- ValueError: If both ``telemetry`` and ``runtime_options`` are
91- provided.
90+ ValueError: If both ```runtime_options`` is a negative value.
9291 """
93- if runtime_options and telemetry :
94- raise ValueError ("Cannot supply both telemetry and runtime_options" )
95-
96- if runtime_options is None :
97- telemetry = telemetry or TelemetryConfig ()
98- runtime_options = RuntimeOptions (telemetry = telemetry )
92+ if worker_heartbeat_interval is None :
93+ heartbeat_millis = None
9994 else :
100- telemetry = runtime_options .telemetry
95+ if worker_heartbeat_interval <= timedelta (0 ):
96+ raise ValueError ("worker_heartbeat_interval must be positive" )
97+ heartbeat_millis = int (worker_heartbeat_interval .total_seconds () * 1000 )
98+ if heartbeat_millis == 0 :
99+ heartbeat_millis = 1
100+
101+ self ._heartbeat_millis = heartbeat_millis
101102
102- self ._core_runtime = temporalio .bridge .runtime .Runtime (
103- options = runtime_options ._to_bridge_config ()
103+ runtime_options = temporalio .bridge .runtime .RuntimeOptions (
104+ telemetry = telemetry ._to_bridge_config (),
105+ worker_heartbeat_interval_millis = heartbeat_millis ,
104106 )
107+
108+ self ._core_runtime = temporalio .bridge .runtime .Runtime (options = runtime_options )
105109 if isinstance (telemetry .metrics , MetricBuffer ):
106110 telemetry .metrics ._runtime = self
107111 core_meter = temporalio .bridge .metric .MetricMeter .create (self ._core_runtime )
@@ -415,34 +419,6 @@ def _to_bridge_config(self) -> temporalio.bridge.runtime.TelemetryConfig:
415419 )
416420
417421
418- @dataclass (frozen = True )
419- class RuntimeOptions :
420- """Configuration for runtime initialization."""
421-
422- telemetry : TelemetryConfig = field (default_factory = TelemetryConfig )
423- """Telemetry configuration applied to the runtime."""
424-
425- worker_heartbeat_interval : Optional [timedelta ] = timedelta (seconds = 30 )
426- """Interval for worker heartbeats. ``None`` disables heartbeating."""
427-
428- def _to_bridge_config (self ) -> temporalio .bridge .runtime .RuntimeOptions :
429- heartbeat_millis : Optional [int ]
430- if self .worker_heartbeat_interval is None :
431- heartbeat_millis = None
432- else :
433- if self .worker_heartbeat_interval <= timedelta (0 ):
434- raise ValueError ("worker_heartbeat_interval must be positive" )
435- heartbeat_millis = int (
436- self .worker_heartbeat_interval .total_seconds () * 1000
437- )
438- if heartbeat_millis == 0 :
439- heartbeat_millis = 1
440- return temporalio .bridge .runtime .RuntimeOptions (
441- telemetry = self .telemetry ._to_bridge_config (),
442- worker_heartbeat_interval_millis = heartbeat_millis ,
443- )
444-
445-
446422BufferedMetricKind = NewType ("BufferedMetricKind" , int )
447423"""Representation of a buffered metric kind."""
448424
0 commit comments