Sha256: 1320d5aa20e460deb5bfa1d65ff4166500ec62de26c24ac125a25cad3c73817f

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

module ForemanTasks

  # wrap the dynflow persistence to reflect the changes to execution plan
  # in the Task model. This is probably a temporary solution and
  # Dynflow will probably get more events-based API but it should be enought
  # for start, until the requiements on the API are clear enough.
  class Dynflow::Persistence < ::Dynflow::PersistenceAdapters::Sequel

    def save_execution_plan(execution_plan_id, value)
      super.tap do
        begin
          on_execution_plan_save(execution_plan_id, value)
        rescue => e
          ForemanTasks.dynflow.world.logger.error('Error on on_execution_plan_save event')
          ForemanTasks.dynflow.world.logger.error(e.message)
          ForemanTasks.dynflow.world.logger.error(e.backtrace.join("\n"))
        end
      end
    end

    def on_execution_plan_save(execution_plan_id, data)
      # We can load the data unless the execution plan was properly planned and saved
      # including its steps
      if data[:state] == :pending
        task = ::ForemanTasks::Task::DynflowTask.new
        task.update_from_dynflow(data, false)
        Lock.owner!(::User.current, task.id) if ::User.current
      elsif data[:state] != :planning
        if task = ::ForemanTasks::Task::DynflowTask.find_by_external_id(execution_plan_id)
	  unless task.state.to_s == data[:state].to_s
            task.update_from_dynflow(data, true)
	  end
        end
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman-tasks-0.5.5 lib/foreman_tasks/dynflow/persistence.rb
foreman-tasks-0.5.4 lib/foreman_tasks/dynflow/persistence.rb
foreman-tasks-0.5.3 lib/foreman_tasks/dynflow/persistence.rb
foreman-tasks-0.5.2 lib/foreman_tasks/dynflow/persistence.rb
foreman-tasks-0.5.1 lib/foreman_tasks/dynflow/persistence.rb
foreman-tasks-0.5.0 lib/foreman_tasks/dynflow/persistence.rb