Class: ActiveMessaging::Worker

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/activemessaging/threaded_poller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(poller, options) ⇒ Worker

Returns a new instance of Worker.



203
204
205
206
# File 'lib/activemessaging/threaded_poller.rb', line 203

def initialize(poller, options)
  self.poller = poller
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



201
202
203
# File 'lib/activemessaging/threaded_poller.rb', line 201

def options
  @options
end

#pollerObject

Returns the value of attribute poller.



201
202
203
# File 'lib/activemessaging/threaded_poller.rb', line 201

def poller
  @poller
end

Instance Method Details

#execute(message) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/activemessaging/threaded_poller.rb', line 208

def execute(message)
  begin
    ::ActiveMessaging::Gateway.dispatch(message)
  rescue Object => err
    logger.error("ActiveMessaging::Worker.execute error - #{err.inspect}")
    abort(err)
  ensure
    ::ActiveRecord::Base.clear_active_connections! if defined?(::ActiveRecord)
  end

  poller.executed!(current_actor)
end

#inspectObject



221
222
223
# File 'lib/activemessaging/threaded_poller.rb', line 221

def inspect
  "#<Worker #{to_s}>"
end

#loggerObject



229
# File 'lib/activemessaging/threaded_poller.rb', line 229

def logger; ::ActiveMessaging.logger; end

#to_sObject



225
226
227
# File 'lib/activemessaging/threaded_poller.rb', line 225

def to_s
  @str ||= "#{Process.pid}-#{Thread.current.object_id}:#{self.object_id}"
end