Class: SidekiqBackgrounder::Worker
- Inherits:
-
Object
- Object
- SidekiqBackgrounder::Worker
- Includes:
- Sidekiq::Worker
- Defined in:
- lib/sidekiq_backgrounder.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#exception_handler_method ⇒ Object
readonly
Returns the value of attribute exception_handler_method.
-
#gid_str ⇒ Object
readonly
Returns the value of attribute gid_str.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize ⇒ Worker
constructor
A new instance of Worker.
- #perform(identifier, method, method_args = nil, raise_exception = true, exception_handler_method = nil) ⇒ Object
Constructor Details
#initialize ⇒ Worker
Returns a new instance of Worker.
15 16 17 18 |
# File 'lib/sidekiq_backgrounder.rb', line 15 def initialize @config = SidekiqBackgrounder.configuration @logger = config.logger end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/sidekiq_backgrounder.rb', line 13 def config @config end |
#exception_handler_method ⇒ Object (readonly)
Returns the value of attribute exception_handler_method.
13 14 15 |
# File 'lib/sidekiq_backgrounder.rb', line 13 def exception_handler_method @exception_handler_method end |
#gid_str ⇒ Object (readonly)
Returns the value of attribute gid_str.
13 14 15 |
# File 'lib/sidekiq_backgrounder.rb', line 13 def gid_str @gid_str end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
13 14 15 |
# File 'lib/sidekiq_backgrounder.rb', line 13 def logger @logger end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
13 14 15 |
# File 'lib/sidekiq_backgrounder.rb', line 13 def method @method end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
13 14 15 |
# File 'lib/sidekiq_backgrounder.rb', line 13 def object @object end |
Instance Method Details
#perform(identifier, method, method_args = nil, raise_exception = true, exception_handler_method = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sidekiq_backgrounder.rb', line 20 def perform(identifier, method, method_args = nil, raise_exception = true, exception_handler_method = nil) @object = if identifier.match(/gid:/) GlobalID.new(identifier).find rescue nil else identifier.constantize.new end logger.debug("#{object.class}: found/instantiated object ") if object.blank? logger.error "#{identifier.inspect} not found to call #{method.to_s.inspect} on, exiting..." return end @exception_handler_method = exception_handler_method begin logger.info "#{self.class}: running: #{object.class rescue object.inspect}##{method}, " + "method_args: #{method_args.inspect}" object.public_send(method, *method_args) rescue Exception => e if exception_handler_method.present? object.public_send(exception_handler_method, e) else msg = "class: \"#{object.to_gid.to_str rescue object.class.to_s || "N/A"}\", method: \"#{method}\" " + "method_args: #{method_args.inspect} encountered_error: #{extract_errors_with_backtrace(e)}" if defined?(:Honeybadger) && config.use_honeybadger Honeybadger.notify( msg, force: true, fingerprint: Digest::SHA1.hexdigest(msg), error_class: "SideKiqBackgrounder::Worker Error", ) end unless raise_exception logger.error msg return end raise SidekiqBackgrounder::Error.new(msg) end end end |