Class: Djwrapper::Job

Inherits:
Struct
  • Object
show all
Defined in:
lib/djwrapper/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name

Returns:

  • (Object)

    the current value of class_name



30
31
32
# File 'lib/djwrapper/job.rb', line 30

def class_name
  @class_name
end

#method_nameObject

Returns the value of attribute method_name

Returns:

  • (Object)

    the current value of method_name



30
31
32
# File 'lib/djwrapper/job.rb', line 30

def method_name
  @method_name
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



30
31
32
# File 'lib/djwrapper/job.rb', line 30

def params
  @params
end

Instance Method Details

#performObject

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