Class: Actions::TriggerProxyBatch
- Inherits:
-
Base
- Object
- Dynflow::Action
- Base
- Actions::TriggerProxyBatch
show all
- Defined in:
- app/lib/actions/trigger_proxy_batch.rb
Overview
This action plans proxy tasks in batches. It needs to be manually notified about the next batch being available by sending a TriggerNextBatch event.
The ProxyAction needs to be planned with `:use_batch_triggering => true` to activate the feature
Constant Summary
collapse
- TriggerNextBatch =
Algebrick.type do
fields! batches: Integer
end
- TriggerLastBatch =
Algebrick.atom
Instance Method Summary
collapse
Methods inherited from Base
#already_running?, #humanized_errors, #humanized_input, #humanized_name, #humanized_output, #notify_paused, #serializer_class, #task, #task_input, #task_output
included, #log_task_state_change
Instance Method Details
#check_finish ⇒ Object
53
54
55
56
57
58
59
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 53
def check_finish
if output[:planned_count] + output[:failed_count] + batch_size >= input[:total_count]
trigger_remote_tasks_batch and on_finish
else
suspend
end
end
|
#done? ⇒ Boolean
61
62
63
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 61
def done?
output[:planned_count] + output[:failed_count] >= input[:total_count]
end
|
#init_counts ⇒ Object
48
49
50
51
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 48
def init_counts
output[:planned_count] = 0
output[:failed_count] = 0
end
|
#on_finish ⇒ Object
69
70
71
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 69
def on_finish
end
|
#remote_tasks ⇒ Object
65
66
67
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 65
def remote_tasks
task.remote_sub_tasks
end
|
#run(event = nil) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 12
def run(event = nil)
case event
when nil
if output[:planned_count]
check_finish
else
init_counts and suspend
end
when TriggerNextBatch
trigger_remote_tasks_batches(event.batches) and suspend
when TriggerLastBatch
trigger_remote_tasks_batch and on_finish
when ::Dynflow::Action::Skip
end
end
|
#trigger_remote_tasks_batch ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 33
def trigger_remote_tasks_batch
batch = remote_tasks.pending.order(:proxy_url, :id).first(batch_size)
batch.group_by(&:operation).each do |operation, group|
ForemanTasks::RemoteTask.batch_trigger(operation, group)
end
output[:planned_count] += batch.size
rescue => e
action_logger.warn "Could not trigger task on the smart proxy: #{e.message}"
batch.each { |remote_task| remote_task.update_from_batch_trigger({}) }
output[:failed_count] += batch.size
end
|
#trigger_remote_tasks_batches(amount = 1) ⇒ Object
29
30
31
|
# File 'app/lib/actions/trigger_proxy_batch.rb', line 29
def trigger_remote_tasks_batches(amount = 1)
amount.times { trigger_remote_tasks_batch }
end
|