Class: Sidekiq::Processor

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Util
Defined in:
lib/sidekiq/processor.rb

Constant Summary

Constants included from Util

Util::EXPIRY

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#constantize, #logger, #process_id, #redis, #watchdog

Constructor Details

#initialize(boss) ⇒ Processor

Returns a new instance of Processor.



26
27
28
# File 'lib/sidekiq/processor.rb', line 26

def initialize(boss)
  @boss = boss
end

Class Method Details

.default_middlewareObject



16
17
18
19
20
21
22
23
24
# File 'lib/sidekiq/processor.rb', line 16

def self.default_middleware
  Middleware::Chain.new do |m|
    m.add Middleware::Server::ExceptionHandler
    m.add Middleware::Server::Logging
    m.add Middleware::Server::RetryJobs
    m.add Middleware::Server::ActiveRecord
    m.add Middleware::Server::Timeout
  end
end

Instance Method Details

#inspectObject



44
45
46
# File 'lib/sidekiq/processor.rb', line 44

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

#process(msg, queue) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sidekiq/processor.rb', line 30

def process(msg, queue)
  klass  = constantize(msg['class'])
  worker = klass.new
  defer do
    stats(worker, msg, queue) do
      Sidekiq.server_middleware.invoke(worker, msg, queue) do
        worker.perform(*msg['args'])
      end
    end
  end
  @boss.processor_done!(current_actor)
end

#to_sObject



48
49
50
# File 'lib/sidekiq/processor.rb', line 48

def to_s
  @str ||= "#{hostname}:#{process_id}-#{Thread.current.object_id}:default"
end