diff --git a/app/lib/actions/entry_action.rb b/app/lib/actions/entry_action.rb index a3e35926c..46484a45e 100644 --- a/app/lib/actions/entry_action.rb +++ b/app/lib/actions/entry_action.rb @@ -57,7 +57,7 @@ def self.all_action_names end def delay(_schedule_options, *args) - Actions::Serializers::ActiveRecordSerializer.new args + Serializers::ActiveRecordSerializer.new args end end diff --git a/app/models/foreman_tasks/task/dynflow_task.rb b/app/models/foreman_tasks/task/dynflow_task.rb index cd2ce8645..692f50d81 100644 --- a/app/models/foreman_tasks/task/dynflow_task.rb +++ b/app/models/foreman_tasks/task/dynflow_task.rb @@ -109,5 +109,11 @@ def self.consistency_check end return fixed_count end + + def self.new_for_execution_plan(execution_plan_id, data) + self.new(:external_id => execution_plan_id, + :state => data[:state].to_s, + :result => data[:result].to_s) + end end end diff --git a/lib/foreman_tasks/dynflow/persistence.rb b/lib/foreman_tasks/dynflow/persistence.rb index 66cfa55f9..c07f10ea8 100644 --- a/lib/foreman_tasks/dynflow/persistence.rb +++ b/lib/foreman_tasks/dynflow/persistence.rb @@ -23,23 +23,22 @@ def save_execution_plan(execution_plan_id, value) 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] == :scheduled + case data[:state] + when :pending + ForemanTasks::Task::DynflowTask.new_for_execution_plan(execution_plan_id, data).save! + when :scheduled delayed_plan = load_delayed_plan(execution_plan_id) raise "Plan is delayed but the delay record is missing" if delayed_plan.nil? # TODO: Rework this delayed_plan = ::Dynflow::DelayedPlan.new_from_hash(ForemanTasks.dynflow.world, delayed_plan) - task = ::ForemanTasks::Task::DynflowTask.new + task = ::ForemanTasks::Task::DynflowTask.find_by_external_id(execution_plan_id) task.update_from_dynflow(data.merge(:start_at => delayed_plan.start_at, :start_before => delayed_plan.start_before)) - elsif data[:state] == :planning - task = if data[:execution_history].length > 0 && data[:execution_history].first[:name] == 'delay' - ::ForemanTasks::Task::DynflowTask.find_by_external_id(execution_plan_id) - else - ::ForemanTasks::Task::DynflowTask.new - end + when :planning + task = ::ForemanTasks::Task::DynflowTask.find_by_external_id(execution_plan_id) task.update_from_dynflow(data) Lock.owner!(::User.current, task.id) if ::User.current - elsif data[:state] != :pending + else 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)