Skip to content

Commit

Permalink
Make dynflow task accessible in delay
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Aug 19, 2015
1 parent 1f77e73 commit 30629af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/lib/actions/entry_action.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/models/foreman_tasks/task/dynflow_task.rb
Expand Up @@ -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
17 changes: 8 additions & 9 deletions lib/foreman_tasks/dynflow/persistence.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 30629af

Please sign in to comment.