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
|
# File 'lib/state_machine_job/macro.rb', line 16
def result(job_result, options = {})
if job_result.is_a?(Hash)
if job_result.size > 1
raise("Use an explicit :state option when passing additional options.\n\n result :ok, :state => :done, :if => ...\n NOT result :ok => :done, :if => ...\n\n")
end
return result(job_result.first.first, :state => job_result.first.last)
end
if options[:retry_if_state] && options[:retry_after]
raise('Combining the :retry_after and :retry_on_state options is not supported at the moment.')
end
if options[:retry_if_state] && !@on_enter_state
raise('The on_enter call must appear above any result using the :retry_if_state option.')
end
if options[:if] && options[:retry_after]
raise('Combining the :retry_after and :if options is not supported at the moment.')
end
on_enter_state = @on_enter_state
if options[:state]
@state_machine.event(StateMachineJob.result_event_name(@job, job_result)) do
if options[:retry_if_state]
transition options[:retry_if_state] => on_enter_state
end
transition(all => options[:state], :if => options[:if])
end
elsif options[:retry_after]
@state_machine.define_helper :instance, StateMachineJob.result_method_name(@job, job_result) do |_machine, object|
@job.set(wait: options[:retry_after]).perform_later(object, @payload.call(object))
end
end
end
|