Class: Djwrapper::Job
- Inherits:
-
Struct
- Object
- Struct
- Djwrapper::Job
- Defined in:
- lib/djwrapper/job.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#perform ⇒ Object
instance methods.
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name
30 31 32 |
# File 'lib/djwrapper/job.rb', line 30 def class_name @class_name end |
#method_name ⇒ Object
Returns the value of attribute method_name
30 31 32 |
# File 'lib/djwrapper/job.rb', line 30 def method_name @method_name end |
#params ⇒ Object
Returns the value of attribute params
30 31 32 |
# File 'lib/djwrapper/job.rb', line 30 def params @params end |
Instance Method Details
#perform ⇒ Object
instance methods
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/djwrapper/job.rb', line 43 def perform # default parameters params ||= {} method_name ||= "process!" ret = false #Rails.logger.info("Djwrapper::Job: starting 'perform' method ...") raise "class_name must be a String!" unless class_name.is_a?(String) raise "params must be a Hash!" unless params.is_a?(Hash) klazz = eval(class_name) # u kidding me? :'( #>> Djwrapper::DelayedBackgroundProcess.is_a?(Djwrapper::DelayedBackgroundProcess) #=> false #raise "class #{klazz.to_s} must be subclass of ::Djwrapper::BackgroundProcess" unless klazz.is_a?(Djwrapper::BackgroundProcess) #Rails.logger.info("Djwrapper::Job: Calling '#{method_name}' method on class #{klazz.to_s} with parameters: #{params}") # dont wrap this in a begin rescue end block. # it wont crash since it's a delayed job, and otherwise we could not ask DJ what the error was. # oh wait, we can just wrap it, and then re-raise the exception. # NICE DUDE ret = nil begin ret = klazz.send(method_name, params) klazz.send("log", "Job done.") rescue => e klazz.send("log", "Job failed :(") raise e end # return code. klazz.send("log", "Job returned: #{ret.inspect}") #Rails.logger.info("Djwrapper::Job: done with 'perform' method.") ret end |