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.
-
#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 |
#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
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/marty/promise_job.rb', line 16 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
60 61 62 |
# File 'lib/marty/promise_job.rb', line 60 def max_attempts 1 end |
#perform ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/marty/promise_job.rb', line 27 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 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 |