Sha256: 3510bc49b285dcc9874f21783022db8bef0d3e191dfd9fda850f2c85ef7550c1

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'foreman_tasks/version'
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)
    # TODO raise aggregation error when there are failed run-steps
    trigger_task false, action, *args, &block
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman-tasks-0.2.1 lib/foreman_tasks.rb
foreman-tasks-0.2.0 lib/foreman_tasks.rb