Class: Sidekiq::Processor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

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

Constructor Details

#initialize(boss) ⇒ Processor

Returns a new instance of Processor.


30
31
32
33
# File 'lib/sidekiq/processor.rb', line 30

def initialize(boss)
  @boss = boss
  redis.sadd('workers', self)
end

Instance Attribute Details

#msgObject

Returns the value of attribute msg


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

def msg
  @msg
end

#queueObject

Returns the value of attribute queue


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

def queue
  @queue
end

Class Method Details

.default_middlewareObject


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

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

.middlewareObject


15
16
17
# File 'lib/sidekiq/processor.rb', line 15

def self.middleware
  raise "Sidekiq::Processor.middleware is now Sidekiq.server_middleware"
end

Instance Method Details

#inspectObject


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

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

#process(msg, queue) ⇒ Object


35
36
37
38
39
40
41
42
43
44
# File 'lib/sidekiq/processor.rb', line 35

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

#to_sObject


51
52
53
# File 'lib/sidekiq/processor.rb', line 51

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