module ForemanTasks
Constants
- VERSION
Public Class Methods
async_task(action, *args, &block)
click to toggle source
# File lib/foreman_tasks.rb, line 50 def self.async_task(action, *args, &block) trigger_task true, action, *args, &block end
chain(dependencies, action, *args)
click to toggle source
Chain a task to wait for dependency task(s) to finish before executing. The chained task remains 'scheduled' until all dependencies reach 'stopped' state.
@param dependencies [ForemanTasks::Task, Array<ForemanTasks::Task>, ActiveRecord::Relation]
Dependency ForemanTasks task object(s) or an ActiveRecord relation of tasks.
@param action [Class] Action class to execute @param args Arguments to pass to the action @return [ForemanTasks::Task::DynflowTask] The chained task
# 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)
click to toggle source
# 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
dynflow()
click to toggle source
# File lib/foreman_tasks.rb, line 15 def self.dynflow @dynflow ||= ForemanTasks::Dynflow.new(nil, ForemanTasks::Dynflow::Configuration.new) end
rails_safe_trigger_task() { || ... }
click to toggle source
# 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)
click to toggle source
# 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 # rubocop:disable Lint/SuppressedException end
sync_task(action, *args, &block)
click to toggle source
# 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()
click to toggle source
# File lib/foreman_tasks/engine.rb, line 206 def self.table_name_prefix 'foreman_tasks_' end
trigger(action, *args, &block)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Public Instance Methods
use_relative_model_naming()
click to toggle source
# File lib/foreman_tasks/engine.rb, line 210 def use_relative_model_naming true end