Class: Sidekiq::Processor
- Inherits:
-
Object
- Object
- Sidekiq::Processor
- Includes:
- Component
- Defined in:
- lib/sidekiq/processor.rb
Overview
The Processor is a standalone thread which:
- fetches a job from Redis
- executes the job
- instantiate the job class
- run the middleware chain
- call #perform
A Processor can exit due to shutdown or due to an error during job execution.
If an error occurs in the job execution, the Processor calls the Manager to create a new one to replace itself and exits.
Defined Under Namespace
Classes: Counter, SharedWorkState
Instance Attribute Summary collapse
-
#capsule ⇒ Object
readonly
Returns the value of attribute capsule.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Attributes included from Component
Instance Method Summary collapse
-
#initialize(capsule, &block) ⇒ Processor
constructor
A new instance of Processor.
- #kill(wait = false) ⇒ Object
- #start ⇒ Object
- #stopping? ⇒ Boolean
- #terminate(wait = false) ⇒ Object
Methods included from Component
#default_tag, #fire_event, #handle_exception, #hostname, #identity, #inspect, #logger, #mono_ms, #process_nonce, #real_ms, #redis, #safe_thread, #tid, #watchdog
Constructor Details
#initialize(capsule, &block) ⇒ Processor
Returns a new instance of Processor.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sidekiq/processor.rb', line 32 def initialize(capsule, &block) @config = capsule.config @capsule = capsule @callback = block @down = false @done = false @job = nil @thread = nil @reloader = Sidekiq.default_configuration[:reloader] @job_logger = (capsule.config[:job_logger] || Sidekiq::JobLogger).new(@config) @retrier = Sidekiq::JobRetry.new(@capsule) end |
Instance Attribute Details
#capsule ⇒ Object (readonly)
Returns the value of attribute capsule.
30 31 32 |
# File 'lib/sidekiq/processor.rb', line 30 def capsule @capsule end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
29 30 31 |
# File 'lib/sidekiq/processor.rb', line 29 def job @job end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
28 29 30 |
# File 'lib/sidekiq/processor.rb', line 28 def thread @thread end |
Instance Method Details
#kill(wait = false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sidekiq/processor.rb', line 51 def kill(wait = false) @done = true return unless @thread # unlike the other actors, terminate does not wait # for the thread to finish because we don't know how # long the job will take to finish. Instead we # provide a `kill` method to call after the shutdown # timeout passes. @thread.raise ::Sidekiq::Shutdown @thread.value if wait end |
#start ⇒ Object
67 68 69 |
# File 'lib/sidekiq/processor.rb', line 67 def start @thread ||= safe_thread("#{capsule.name}/processor", &method(:run)) end |
#stopping? ⇒ Boolean
63 64 65 |
# File 'lib/sidekiq/processor.rb', line 63 def stopping? @done end |
#terminate(wait = false) ⇒ Object
45 46 47 48 49 |
# File 'lib/sidekiq/processor.rb', line 45 def terminate(wait = false) @done = true return unless @thread @thread.value if wait end |