Class: Delorean::BaseModule::NodeCall
- Inherits:
-
Object
- Object
- Delorean::BaseModule::NodeCall
- Defined in:
- lib/marty/promise_job.rb
Instance Method Summary collapse
-
#initialize(_e, engine, node, params) ⇒ NodeCall
constructor
A new instance of NodeCall.
-
#|(args) ⇒ Object
Monkey-patch ‘|’ method for Delorean NodeCall to create promise jobs and return promise proxy objects.
Constructor Details
#initialize(_e, engine, node, params) ⇒ NodeCall
Returns a new instance of NodeCall.
4 5 6 7 8 9 10 11 |
# File 'lib/marty/promise_job.rb', line 4 def initialize(_e, engine, node, params) super # If call has a promise_id (i.e. is from a promise) then that's # our parent. Otherwise, we use its parent as our parent. params[:_parent_id] = _e[:_promise_id] || _e[:_parent_id] params[:_user_id] = _e[:_user_id] || Mcfly.whodunnit.try(:id) end |
Instance Method Details
#|(args) ⇒ Object
Monkey-patch ‘|’ method for Delorean NodeCall to create promise jobs and return promise proxy objects.
15 16 17 18 19 20 21 22 23 24 25 26 27 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/marty/promise_job.rb', line 15 def |(args) if args.is_a?(String) attr = args args = [attr] else raise "bad arg to %" unless args.is_a?(Array) attr = nil end script, tag = engine.module_name, engine.sset.tag nn = node.is_a?(Class) ? node.name : node.to_s begin # make sure params is serialzable before starting a Job Marshal.dump(params) rescue => exc raise "non-serializable parameters" end title = params["p_title"] || "#{script}::#{nn.demodulize}" timeout = params["p_timeout"] || Marty::Promise::DEFAULT_PROMISE_TIMEOUT hook = params["p_hook"] promise = Marty::Promise. create(title: title, user_id: params[:_user_id], parent_id: params[:_parent_id], ) params[:_promise_id] = promise.id begin job = Delayed::Job.enqueue Marty::PromiseJob. new(promise, title, script, tag, nn, params, args, hook) rescue => exc # log "CALLERR #{exc}" res = Delorean::Engine.grok_runtime_exception(exc) promise.set_start promise.set_result(res) # log "CALLERRSET #{res}" raise end # keep a reference to the job. This is needed in case we want to # work off a promise job that we're waiting for and which hasn't # been reserved yet. promise.job_id = job.id promise.save! evh = params["p_event"] if evh event, klass, subject_id, operation = evh.values_at("event", "klass", "id", "operation") if event event.promise_id = promise.id event.save! else event = Marty::Event. create!(promise_id: promise.id, klass: klass, subject_id: subject_id, enum_event_operation: operation) end end Marty::PromiseProxy.new(promise.id, timeout, attr) end |