Sha256: b241a1a463a980e5fd80ffe4090dae47ff3bd7ec2fa95d2871dc88b7e88ab03a

Contents?: true

Size: 1.4 KB

Versions: 14

Compression:

Stored size: 1.4 KB

Contents

require 'foreman_tasks/version'
require 'foreman_tasks/task_error'
require 'foreman_tasks/engine'
require 'foreman_tasks/dynflow'
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
  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) 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.where(:external_id => id).first!
          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

  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

14 entries across 14 versions & 1 rubygems

Version Path
foreman-tasks-0.8.0 lib/foreman_tasks.rb
foreman-tasks-0.7.20 lib/foreman_tasks.rb
foreman-tasks-0.7.19 lib/foreman_tasks.rb
foreman-tasks-0.7.18 lib/foreman_tasks.rb
foreman-tasks-0.7.17 lib/foreman_tasks.rb
foreman-tasks-0.7.16 lib/foreman_tasks.rb
foreman-tasks-0.7.15 lib/foreman_tasks.rb
foreman-tasks-0.7.14 lib/foreman_tasks.rb
foreman-tasks-0.7.13 lib/foreman_tasks.rb
foreman-tasks-0.7.12 lib/foreman_tasks.rb
foreman-tasks-0.7.11 lib/foreman_tasks.rb
foreman-tasks-0.7.10 lib/foreman_tasks.rb
foreman-tasks-0.7.9 lib/foreman_tasks.rb
foreman-tasks-0.7.8 lib/foreman_tasks.rb