Sha256: 3e17e894990eab90b8ef453152e04add97031d99234d99f157ad041ef000a9a4

Contents?: true

Size: 1.79 KB

Versions: 13

Compression:

Stored size: 1.79 KB

Contents

require 'foreman_tasks/version'
require 'foreman_tasks/task_error'
require 'foreman_tasks/engine'
require 'foreman_tasks/dynflow'
require 'foreman_tasks/dynflow/configuration'
require 'foreman_tasks/triggers'
require 'foreman_tasks/authorizer_ext'
require 'foreman_tasks/cleaner'

module ForemanTasks
  extend Algebrick::TypeCheck
  extend Algebrick::Matching

  def self.dynflow
    @dynflow ||= ForemanTasks::Dynflow.new(nil, ForemanTasks::Dynflow::Configuration.new)
  end

  def self.trigger(action, *args, &block)
    dynflow.world.trigger action, *args, &block
  end

  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|
              finished.wait if async == false
              ForemanTasks::Task::DynflowTask.where(:external_id => id).first!
            end)
    end
  end

  def self.rails_safe_trigger_task
    if Rails::VERSION::MAJOR > 4
      ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
        yield
      end
    else
      yield
    end
  end

  def self.async_task(action, *args, &block)
    trigger_task true, action, *args, &block
  end

  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

  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
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
foreman-tasks-0.11.3 lib/foreman_tasks.rb
foreman-tasks-0.13.1 lib/foreman_tasks.rb
foreman-tasks-0.13.0 lib/foreman_tasks.rb
foreman-tasks-0.12.2 lib/foreman_tasks.rb
foreman-tasks-0.11.2 lib/foreman_tasks.rb
foreman-tasks-0.12.1 lib/foreman_tasks.rb
foreman-tasks-0.12.0 lib/foreman_tasks.rb
foreman-tasks-0.11.1 lib/foreman_tasks.rb
foreman-tasks-0.10.9 lib/foreman_tasks.rb
foreman-tasks-0.11.0 lib/foreman_tasks.rb
foreman-tasks-0.10.8 lib/foreman_tasks.rb
foreman-tasks-0.10.7 lib/foreman_tasks.rb
foreman-tasks-0.10.6 lib/foreman_tasks.rb