Class: Marty::PromiseJob
- Inherits:
-
Struct
- Object
- Struct
- Marty::PromiseJob
- Defined in:
- lib/marty/promise_job.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#hook ⇒ Object
Returns the value of attribute hook.
-
#max_run_time ⇒ Object
Returns the value of attribute max_run_time.
-
#node ⇒ Object
Returns the value of attribute node.
-
#params ⇒ Object
Returns the value of attribute params.
-
#promise ⇒ Object
Returns the value of attribute promise.
-
#sname ⇒ Object
Returns the value of attribute sname.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#enqueue(job) ⇒ Object
def log(msg) open(‘/tmp/dj.out’, ‘a’) { |f| f.puts msg } end.
- #max_attempts ⇒ Object
- #perform ⇒ Object
- #process_hook(res) ⇒ Object
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def attrs @attrs end |
#hook ⇒ Object
Returns the value of attribute hook
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def hook @hook end |
#max_run_time ⇒ Object
Returns the value of attribute max_run_time
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def max_run_time @max_run_time end |
#node ⇒ Object
Returns the value of attribute node
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def node @node end |
#params ⇒ Object
Returns the value of attribute params
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def params @params end |
#promise ⇒ Object
Returns the value of attribute promise
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def promise @promise end |
#sname ⇒ Object
Returns the value of attribute sname
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def sname @sname end |
#tag ⇒ Object
Returns the value of attribute tag
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def tag @tag end |
#title ⇒ Object
Returns the value of attribute title
3 4 5 |
# File 'lib/marty/promise_job.rb', line 3 def title @title end |
Instance Method Details
#enqueue(job) ⇒ Object
def log(msg)
open('/tmp/dj.out', 'a') { |f| f.puts msg }
end
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/marty/promise_job.rb', line 17 def enqueue(job) config = Rails.configuration.marty hooks = config.promise_job_enqueue_hooks return if hooks.blank? hooks.each do |hook| hook.call(job) end end |
#max_attempts ⇒ Object
70 71 72 |
# File 'lib/marty/promise_job.rb', line 70 def max_attempts 1 end |
#perform ⇒ Object
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 |
# File 'lib/marty/promise_job.rb', line 28 def perform # log "PERF #{Process.pid} #{title}" promise.set_start begin # in case the job writes to the the database Mcfly.whodunnit = promise.user engine = Marty::ScriptSet.new(tag).get_engine(sname) attrs_eval = engine.evaluate(node, attrs, params) res = attrs.zip(attrs_eval).each_with_object({}) do |(attr, val), h| h[attr] = val end # log "DONE #{Process.pid} #{promise.id} #{Time.now.to_f} #{res}" rescue ::Delayed::WorkerTimeout => e msg = ::Marty::Promise.(promise) timeout_error = StandardError.new( "#{msg} (Triggered by #{e.class})" ) timeout_error.set_backtrace(e.backtrace) res = Delorean::Engine.grok_runtime_exception(timeout_error) rescue StandardError => e res = Delorean::Engine.grok_runtime_exception(e) # log "ERR- #{Process.pid} #{promise.id} #{Time.now.to_f} #{e}" end promise.set_result(res) process_hook(res) end |