Module: ForemanTasks
- Extended by:
- Algebrick::Matching, Algebrick::TypeCheck
- Defined in:
- lib/foreman_tasks.rb,
lib/foreman_tasks/engine.rb,
lib/foreman_tasks/cleaner.rb,
lib/foreman_tasks/dynflow.rb,
lib/foreman_tasks/version.rb,
lib/foreman_tasks/triggers.rb,
lib/foreman_tasks/task_error.rb,
app/models/foreman_tasks/link.rb,
app/models/foreman_tasks/lock.rb,
app/models/foreman_tasks/task.rb,
lib/foreman_tasks/test_helpers.rb,
lib/foreman_tasks/authorizer_ext.rb,
lib/foreman_tasks/test_extensions.rb,
app/models/foreman_tasks/task_group.rb,
app/models/foreman_tasks/triggering.rb,
lib/foreman_tasks/continuous_output.rb,
app/models/foreman_tasks/remote_task.rb,
app/models/foreman_tasks/task/search.rb,
app/helpers/foreman_tasks/tasks_helper.rb,
lib/foreman_tasks/dynflow/configuration.rb,
app/models/foreman_tasks/recurring_logic.rb,
app/models/foreman_tasks/task/summarizer.rb,
app/services/foreman_tasks/proxy_selector.rb,
app/models/foreman_tasks/task/dynflow_task.rb,
app/models/foreman_tasks/task_group_member.rb,
lib/foreman_tasks/dynflow/console_authorizer.rb,
app/controllers/foreman_tasks/react_controller.rb,
app/controllers/foreman_tasks/tasks_controller.rb,
app/helpers/foreman_tasks/foreman_tasks_helper.rb,
app/models/foreman_tasks/task/status_explicator.rb,
app/models/foreman_tasks/concerns/action_subject.rb,
app/models/foreman_tasks/tasks_mail_notification.rb,
app/models/foreman_tasks/concerns/user_extensions.rb,
app/controllers/foreman_tasks/api/tasks_controller.rb,
app/models/foreman_tasks/concerns/action_triggering.rb,
app/models/foreman_tasks/concerns/host_action_subject.rb,
app/models/foreman_tasks/task/task_cancelled_exception.rb,
app/controllers/concerns/foreman_tasks/find_tasks_common.rb,
app/lib/foreman_tasks/concerns/polling_action_extensions.rb,
app/controllers/foreman_tasks/recurring_logics_controller.rb,
app/services/foreman_tasks/troubleshooting_help_generator.rb,
app/controllers/foreman_tasks/concerns/parameters/triggering.rb,
app/models/foreman_tasks/recurring_logic_cancelled_exception.rb,
app/controllers/foreman_tasks/api/recurring_logics_controller.rb,
app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb,
app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb,
app/controllers/foreman_tasks/concerns/parameters/recurring_logic.rb
Defined Under Namespace
Modules: Api, AuthorizerExt, Concerns, FindTasksCommon, ForemanTasksHelper, TaskGroups, TasksHelper, TestExtensions, TestHelpers, Triggers
Classes: ActionRule, Cleaner, CompositeActionRule, ContinuousOutput, Dynflow, Engine, Link, Lock, ProxySelector, ReactController, RecurringLogic, RecurringLogicCancelledException, RecurringLogicsController, RemoteTask, Task, TaskError, TaskGroup, TaskGroupMember, TasksController, TasksMailNotification, Triggering, TroubleshootingHelpGenerator
Constant Summary
collapse
- VERSION =
'12.0.0'.freeze
Class Method Summary
collapse
-
.async_task(action, *args, &block) ⇒ Object
-
.chain(dependencies, action, *args) ⇒ ForemanTasks::Task::DynflowTask
Chain a task to wait for dependency task(s) to finish before executing.
-
.delay(action, delay_options, *args) ⇒ Object
-
.dynflow ⇒ Object
-
.rails_safe_trigger_task ⇒ Object
-
.register_scheduled_task(task_class, cronline) ⇒ Object
-
.sync_task(action, *args, &block) ⇒ Object
-
.table_name_prefix ⇒ Object
-
.trigger(action, *args, &block) ⇒ Object
-
.trigger_task(async, action, *args, &block) ⇒ Object
-
.troubleshooting_url_with_placeholders(value) ⇒ Object
Instance Method Summary
collapse
Class Method Details
.async_task(action, *args, &block) ⇒ Object
50
51
52
|
# File 'lib/foreman_tasks.rb', line 50
def self.async_task(action, *args, &block)
trigger_task true, action, *args, &block
end
|
Chain a task to wait for dependency task(s) to finish before executing. The chained task remains ‘scheduled’ until all dependencies reach ‘stopped’ state.
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/foreman_tasks.rb', line 73
def self.chain(dependencies, action, *args)
plan_uuids =
if dependencies.is_a?(ActiveRecord::Relation)
dependencies.pluck(:external_id)
else
Array(dependencies).map(&:external_id)
end
if plan_uuids.any?(&:blank?)
raise ArgumentError, 'All dependency tasks must have external_id set'
end
result = dynflow.world.chain(plan_uuids, action, *args)
ForemanTasks::Task::DynflowTask.where(:external_id => result.id).first!
end
|
.delay(action, delay_options, *args) ⇒ Object
60
61
62
63
|
# File 'lib/foreman_tasks.rb', line 60
def self.delay(action, delay_options, *args)
result = dynflow.world.delay action, delay_options, *args
ForemanTasks::Task::DynflowTask.where(:external_id => result.id).first!
end
|
.rails_safe_trigger_task ⇒ Object
44
45
46
47
48
|
# File 'lib/foreman_tasks.rb', line 44
def self.rails_safe_trigger_task
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
yield
end
end
|
.register_scheduled_task(task_class, cronline) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/foreman_tasks.rb', line 89
def self.register_scheduled_task(task_class, cronline)
ForemanTasks::RecurringLogic.transaction(isolation: :serializable) do
return if ForemanTasks::RecurringLogic.joins(:tasks)
.where(state: 'active')
.merge(ForemanTasks::Task.where(label: task_class.name))
.exists?
User.as_anonymous_admin do
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
recurring_logic.save!
recurring_logic.start(task_class)
end
end
rescue ActiveRecord::TransactionIsolationError end
|
.sync_task(action, *args, &block) ⇒ Object
54
55
56
57
58
|
# File 'lib/foreman_tasks.rb', line 54
def self.sync_task(action, *args, &block)
trigger_task(false, action, *args, &block).tap do |task|
raise TaskError, task if task.execution_plan.error? || task.execution_plan.result == :warning
end
end
|
.table_name_prefix ⇒ Object
206
207
208
|
# File 'lib/foreman_tasks/engine.rb', line 206
def self.table_name_prefix
'foreman_tasks_'
end
|
.trigger(action, *args, &block) ⇒ Object
19
20
21
|
# File 'lib/foreman_tasks.rb', line 19
def self.trigger(action, *args, &block)
dynflow.world.trigger action, *args, &block
end
|
.trigger_task(async, action, *args, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/foreman_tasks.rb', line 23
def self.trigger_task(async, action, *args, &block)
rails_safe_trigger_task do
Match! async, true, false
match trigger(action, *args, &block),
(on ::Dynflow::World::PlaningFailed.call(error: ~any) do |error|
raise error
end),
(on ::Dynflow::World::Triggered.call(execution_plan_id: ~any, future: ~any) do |id, finished|
unless async
timeout = Setting['foreman_tasks_sync_task_timeout']
finished.wait(timeout)
task = ForemanTasks::Task::DynflowTask.where(:external_id => id).first
if task.nil? || (!task.paused? && task.pending?)
raise Timeout::Error, "The time waiting for task #{task.try(:id)} to finish exceeded the 'foreman_tasks_sync_task_timeout' (#{timeout}s)"
end
end
task || ForemanTasks::Task::DynflowTask.where(:external_id => id).first!
end)
end
end
|
.troubleshooting_url_with_placeholders(value) ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/foreman_tasks/engine.rb', line 214
def self.troubleshooting_url_with_placeholders(value)
return true if value.blank?
test_url = value.dup
test_url.gsub!(/%\{label\}/, 'validation_label')
test_url.gsub!(/%\{version\}/, '1.0')
begin
uri = URI.parse(test_url)
unless (uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)) && !uri.host.nil?
raise URI::InvalidURIError
end
true
rescue URI::InvalidURIError
raise Foreman::SettingValueException, N_("Invalid URL")
end
end
|
Instance Method Details
#use_relative_model_naming ⇒ Object
210
211
212
|
# File 'lib/foreman_tasks/engine.rb', line 210
def use_relative_model_naming
true
end
|