Class: Sidekiq::Processor

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

Overview

The Processor receives a message from the Manager and actually processes it. It instantiates the worker, runs the middleware chain and then calls Sidekiq::Worker#perform.

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

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initialize(boss) ⇒ Processor



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

def initialize(boss)
  @boss = boss
end

Class Method Details

.default_middlewareObject



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

def self.default_middleware
  Middleware::Chain.new do |m|
    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



55
56
57
# File 'lib/sidekiq/processor.rb', line 55

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

#process(msgstr, queue) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sidekiq/processor.rb', line 31

def process(msgstr, queue)
  # Defer worker execution to Celluloid's thread pool since all actor
  # invocations are run within a Fiber, which dramatically limits
  # our stack size.
  defer do
    begin
      msg = Sidekiq.load_json(msgstr)
      klass  = constantize(msg['class'])
      worker = klass.new

      stats(worker, msg, queue) do
        Sidekiq.server_middleware.invoke(worker, msg, queue) do
          worker.perform(*cloned(msg['args']))
        end
      end
    rescue => ex
      handle_exception(ex, msg || { :message => msgstr })
      raise
    end
  end
  @boss.processor_done!(current_actor)
end

#to_sObject



59
60
61
# File 'lib/sidekiq/processor.rb', line 59

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