Class: NNQ::CLI::BaseRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/nnq/cli/base_runner.rb

Overview

Template runner base class for all socket-type CLI runners. Subclasses override #run_loop to implement socket-specific behaviour.

nnq carries one String body per message (no multipart).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, socket_class) ⇒ BaseRunner

Returns a new instance of BaseRunner.

Parameters:

  • config (Config)

    frozen CLI configuration

  • socket_class (Class)

    NNQ socket class to instantiate (e.g. NNQ::PUSH)



21
22
23
24
25
# File 'lib/nnq/cli/base_runner.rb', line 21

def initialize(config, socket_class)
  @config = config
  @klass  = socket_class
  @fmt    = Formatter.new(config.format)
end

Instance Attribute Details

#configConfig (readonly)

Returns frozen CLI configuration.

Returns:

  • (Config)

    frozen CLI configuration



12
13
14
# File 'lib/nnq/cli/base_runner.rb', line 12

def config
  @config
end

#sockObject (readonly)

Returns the NNQ socket instance.

Returns:

  • (Object)

    the NNQ socket instance



16
17
18
# File 'lib/nnq/cli/base_runner.rb', line 16

def sock
  @sock
end

Instance Method Details

#call(task) ⇒ void

This method returns an undefined value.

Runs the full lifecycle: socket setup, peer wait, BEGIN/END blocks, and the main loop.

Parameters:

  • task (Async::Task)

    the parent async task



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nnq/cli/base_runner.rb', line 32

def call(task)
  set_process_title
  setup_socket
  start_event_monitor if config.verbose >= 2
  maybe_start_transient_monitor(task)
  sleep(config.delay) if config.delay && config.recv_only?
  wait_for_peer if needs_peer_wait?
  run_begin_blocks
  run_loop(task)
  run_end_blocks
ensure
  @sock&.close
end