Sha256: 0f76f8c25c37a7541effb6d4f55c9ab768c52584df4f66b88d6cd7780e1ae134

Contents?: true

Size: 1.2 KB

Versions: 28

Compression:

Stored size: 1.2 KB

Contents

require 'foreman_tasks/version'
require 'foreman_tasks/task_error'
require 'foreman_tasks/engine'
require 'foreman_tasks/dynflow'
require 'foreman_tasks/triggers'

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

  def self.dynflow
    @dynflow ||= ForemanTasks::Dynflow.new
  end

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

  def self.trigger_task(async, action, *args, &block)
    Match! async, true, false

    match trigger(action, *args, &block),
          (on ::Dynflow::World::PlaningFailed.(error: ~any) |
                  ::Dynflow::World::ExecutionFailed.(error: ~any) do |error|
            raise error
          end),
          (on ::Dynflow::World::Triggered.(execution_plan_id: ~any, future: ~any) do |id, finished|
            finished.wait if async == false
            ForemanTasks::Task::DynflowTask.find_by_external_id!(id)
          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.new(task) if task.execution_plan.error?
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
foreman-tasks-0.6.10 lib/foreman_tasks.rb
foreman-tasks-0.6.9 lib/foreman_tasks.rb
foreman-tasks-0.6.8 lib/foreman_tasks.rb
foreman-tasks-0.6.7 lib/foreman_tasks.rb
foreman-tasks-0.6.6 lib/foreman_tasks.rb
foreman-tasks-0.6.5 lib/foreman_tasks.rb
foreman-tasks-0.6.4 lib/foreman_tasks.rb
foreman-tasks-0.6.3 lib/foreman_tasks.rb
foreman-tasks-0.6.2 lib/foreman_tasks.rb
foreman-tasks-0.6.1 lib/foreman_tasks.rb
foreman-tasks-0.6.0 lib/foreman_tasks.rb
foreman-tasks-0.5.7 lib/foreman_tasks.rb
foreman-tasks-0.5.6 lib/foreman_tasks.rb
foreman-tasks-0.5.5 lib/foreman_tasks.rb
foreman-tasks-0.5.4 lib/foreman_tasks.rb
foreman-tasks-0.5.3 lib/foreman_tasks.rb
foreman-tasks-0.5.2 lib/foreman_tasks.rb
foreman-tasks-0.5.1 lib/foreman_tasks.rb
foreman-tasks-0.5.0 lib/foreman_tasks.rb
foreman-tasks-0.4.0 lib/foreman_tasks.rb