5
6
7
8
9
10
11
12
13
14
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
|
# File 'app/services/marty/promises/delorean/create.rb', line 5
def self.call(params:, script:, node_name:, attr:, args:, tag:)
default_timeout = Marty::Promise::DEFAULT_PROMISE_TIMEOUT
title = params['p_title'] || "#{script}::#{node_name.demodulize}"
timeout = params['p_timeout'] || default_timeout
hook = params['p_hook']
promise = Marty::Promise.create(
title: title,
user_id: params[:_user_id],
parent_id: params[:_parent_id],
promise_type: 'delorean'
)
params[:_promise_id] = promise.id
begin
promise_job = Marty::PromiseJob.new(
promise,
title,
script,
tag,
node_name,
params,
args,
hook
)
job = Delayed::Job.enqueue(promise_job)
rescue StandardError => e
res = ::Delorean::Engine.grok_runtime_exception(e)
promise.set_start
promise.set_result(res)
raise
end
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
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
|