Class: Wamp::Worker::Runner::Background

Inherits:
Base
  • Object
show all
Defined in:
lib/wamp/worker/runner.rb

Overview

This class monitors the queue and returns the descriptor

Instance Attribute Summary collapse

Attributes inherited from Base

#dispatcher, #name

Instance Method Summary collapse

Methods inherited from Base

#_stop, #active?, #logger, #start, #stop

Constructor Details

#initialize(name, uuid: nil, &callback) ⇒ Background

Constructor

Parameters:

  • name (Symbol)
    • the name of the worker



67
68
69
70
71
72
73
74
# File 'lib/wamp/worker/runner.rb', line 67

def initialize(name, uuid: nil, &callback)
  super name, uuid: uuid

  @callback = callback

  # Log the event
  logger.debug("#{self.class.name} '#{self.name}' created")
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



62
63
64
# File 'lib/wamp/worker/runner.rb', line 62

def callback
  @callback
end

#threadObject (readonly)

Returns the value of attribute thread.



62
63
64
# File 'lib/wamp/worker/runner.rb', line 62

def thread
  @thread
end

Instance Method Details

#_startObject

Starts the background runner



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/wamp/worker/runner.rb', line 78

def _start
  # Start the background thread
  Thread.new do

    # The background thread will infinitely call the callback while the
    # runner is active
    while self.active?
      begin
        self.callback.call(self)
      rescue => e
        logger.error("#{self.class.name} #{e.class.name} - #{e.message}")
      end
    end

  end
end