Module: Sidekiq::Component
- Included in:
- BasicFetch, CLI, JobRetry, Launcher, Manager, Processor, Scheduled::Poller
- Defined in:
- lib/sidekiq/component.rb
Overview
Sidekiq::Component assumes a config instance is available at @config
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #fire_event(event, options = {}) ⇒ Object
- #handle_exception(ex, ctx = {}) ⇒ Object
- #hostname ⇒ Object
- #identity ⇒ Object
- #logger ⇒ Object
- #process_nonce ⇒ Object
- #redis(&block) ⇒ Object
- #safe_thread(name, &block) ⇒ Object
- #tid ⇒ Object
- #watchdog(last_words) ⇒ Object
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/sidekiq/component.rb', line 5 def config @config end |
Instance Method Details
#fire_event(event, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sidekiq/component.rb', line 49 def fire_event(event, = {}) reverse = [:reverse] reraise = [:reraise] arr = config[:lifecycle_events][event] arr.reverse! if reverse arr.each do |block| block.call rescue => ex handle_exception(ex, {context: "Exception during Sidekiq lifecycle event.", event: event}) raise ex if reraise end arr.clear # once we've fired an event, we never fire it again end |
#handle_exception(ex, ctx = {}) ⇒ Object
45 46 47 |
# File 'lib/sidekiq/component.rb', line 45 def handle_exception(ex, ctx = {}) config.handle_exception(ex, ctx) end |
#hostname ⇒ Object
33 34 35 |
# File 'lib/sidekiq/component.rb', line 33 def hostname ENV["DYNO"] || Socket.gethostname end |
#identity ⇒ Object
41 42 43 |
# File 'lib/sidekiq/component.rb', line 41 def identity @@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}" end |
#logger ⇒ Object
21 22 23 |
# File 'lib/sidekiq/component.rb', line 21 def logger config.logger end |
#process_nonce ⇒ Object
37 38 39 |
# File 'lib/sidekiq/component.rb', line 37 def process_nonce @@process_nonce ||= SecureRandom.hex(6) end |
#redis(&block) ⇒ Object
25 26 27 |
# File 'lib/sidekiq/component.rb', line 25 def redis(&block) config.redis(&block) end |
#safe_thread(name, &block) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/sidekiq/component.rb', line 14 def safe_thread(name, &block) Thread.new do Thread.current.name = name watchdog(name, &block) end end |
#tid ⇒ Object
29 30 31 |
# File 'lib/sidekiq/component.rb', line 29 def tid Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36) end |
#watchdog(last_words) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/sidekiq/component.rb', line 7 def watchdog(last_words) yield rescue Exception => ex handle_exception(ex, {context: last_words}) raise ex end |