Class: Temporalio::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/runtime.rb,
lib/temporalio/runtime/metric_buffer.rb

Overview

Runtime for Temporal Ruby SDK.

Only one global Runtime needs to exist. Users are encouraged to use Runtime.default. To configure it, create a runtime before any clients are created, and set it via Runtime.default=. Every time a new runtime is created, a new internal Rust thread pool is created.

Defined Under Namespace

Modules: ConsoleLogFormat Classes: LoggingFilterOptions, LoggingOptions, MetricBuffer, MetricsOptions, OpenTelemetryMetricsOptions, PrometheusMetricsOptions, TelemetryOptions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(telemetry: TelemetryOptions.new, worker_heartbeat_interval: 60, disable_environment_info: false) ⇒ Runtime

Create new Runtime. For most users, this should only be done once globally. In addition to creating a Rust thread pool, this also consumes a Ruby thread for its lifetime.

Parameters:

  • telemetry (TelemetryOptions) (defaults to: TelemetryOptions.new)

    Telemetry options to set.

  • worker_heartbeat_interval (Float, nil) (defaults to: 60)

    Interval for worker heartbeats in seconds. Can be nil to disable heartbeating. Interval must be between 1s and 60s.

  • disable_environment_info (Boolean) (defaults to: false)

    When true, worker heartbeats omit runtime, hosting, and platform information. Defaults to false, which advertises this process as CRuby with RUBY_VERSION.



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/temporalio/runtime.rb', line 350

def initialize(
  telemetry: TelemetryOptions.new,
  worker_heartbeat_interval: 60,
  disable_environment_info: false
)
  if !worker_heartbeat_interval.nil? && !worker_heartbeat_interval.positive?
    raise 'Worker heartbeat interval must be positive'
  end

  # Set runtime on the buffer which will fail if the buffer is used on another runtime
  telemetry.metrics&.buffer&._set_runtime(self)

  @core_runtime = Internal::Bridge::Runtime.new(
    Internal::Bridge::Runtime::Options.new(
      telemetry: telemetry._to_bridge,
      worker_heartbeat_interval:,
      disable_environment_info:,
      runtime_version: RUBY_VERSION
    )
  )
  @metric_meter = Internal::Metric::Meter.create_from_runtime(self) || Metric::Meter.null
  # We need a thread to run the command loop
  # TODO(cretz): Is this something users should be concerned about or need control over?
  Thread.new do
    @core_runtime.run_command_loop
  end
end

Instance Attribute Details

#metric_meterMetric::Meter (readonly)

Returns Metric meter that can create and record metric values.

Returns:

  • (Metric::Meter)

    Metric meter that can create and record metric values.



340
341
342
# File 'lib/temporalio/runtime.rb', line 340

def metric_meter
  @metric_meter
end

Class Method Details

.defaultRuntime

Default runtime, lazily created upon first access. If needing a different default, make sure it is updated via default= before this is called (either directly or as a parameter to something like Client).

Returns:



325
326
327
# File 'lib/temporalio/runtime.rb', line 325

def self.default
  @default ||= Runtime.new
end

.default=(runtime) ⇒ Object

Set the default runtime. Must be called before default accessed.

Parameters:

  • runtime (Runtime)

    Runtime to set as default.

Raises:

  • If default has already been accessed.



333
334
335
336
337
# File 'lib/temporalio/runtime.rb', line 333

def self.default=(runtime)
  raise 'Runtime already set or requested' unless @default.nil?

  @default = runtime
end