Class: BackgroundLite::ResqueHandler
- Defined in:
- lib/background_lite/core_ext/handlers/resque_handler.rb
Overview
This background handler sends the method as well as the arguments through Resque to the background process.
Class Attribute Summary collapse
-
.queue ⇒ Object
Returns the value of attribute queue.
Class Method Summary collapse
-
.decode(message) ⇒ Object
Decodes a marshalled message which was previously sent over Resque.
-
.handle(object, method, args, options = {}) ⇒ Object
Marshals the method and the arguments and sends it through Resque to the background process.
-
.perform(message) ⇒ Object
Executes a marshalled message which was previously sent over Resque, in the context of the object, with all the arguments passed.
Class Attribute Details
.queue ⇒ Object
Returns the value of attribute queue.
8 9 10 |
# File 'lib/background_lite/core_ext/handlers/resque_handler.rb', line 8 def queue @queue end |
Class Method Details
.decode(message) ⇒ Object
Decodes a marshalled message which was previously sent over Resque. Returns an array containing the object, the method name as a string, and the method arguments.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/background_lite/core_ext/handlers/resque_handler.rb', line 21 def self.decode() begin object, method, args, transaction_id = Marshal.load(Base64.decode64()) rescue ArgumentError => e # Marshal.load does not trigger const_missing, so we have to do this # ourselves. e..split(' ').last.constantize retry end [object, method, args, transaction_id] end |
.handle(object, method, args, options = {}) ⇒ Object
Marshals the method and the arguments and sends it through Resque to the background process.
13 14 15 16 |
# File 'lib/background_lite/core_ext/handlers/resque_handler.rb', line 13 def self.handle(object, method, args, = {}) require 'resque' Resque.enqueue(self, Base64.encode64(Marshal.dump([object, method, args, [:transaction_id]]))) end |
.perform(message) ⇒ Object
Executes a marshalled message which was previously sent over Resque, in the context of the object, with all the arguments passed.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/background_lite/core_ext/handlers/resque_handler.rb', line 36 def self.perform() logger = BackgroundLite::Config.default_logger begin object, method, args, transaction_id = self.decode() if logger.debug? logger.debug "--- executing method: #{method}" logger.debug "--- with variables: #{args.inspect}" logger.debug "--- in object: #{object.class.name}, #{object.id}" logger.debug "--- Transaction ID: #{transaction_id}" end object.send(method, *args) logger.debug "--- it happened!" if logger.debug? rescue Exception => e logger.fatal e. logger.fatal e.backtrace "BackgroundLite::#{BackgroundLite::Config.default_error_reporter.to_s.camelize}ErrorReporter".constantize.report(e) raise e end end |