diff --git a/app/controllers/foreman_tasks/tasks_controller.rb b/app/controllers/foreman_tasks/tasks_controller.rb index 3c295b7bf..b972cb47c 100644 --- a/app/controllers/foreman_tasks/tasks_controller.rb +++ b/app/controllers/foreman_tasks/tasks_controller.rb @@ -69,7 +69,7 @@ def resume def unlock if @dynflow_task.paused? - unlock_task(@dynflow_task) + @dynflow_task.halt render json: { statusText: 'OK' } else render json: {}, status: :bad_request @@ -77,8 +77,13 @@ def unlock end def force_unlock - unlock_task(@dynflow_task) - render json: { statusText: 'OK' } + if @dynflow_task.pending? + @dynflow_task.halt + render json: { statusText: 'OK' } + else + # Cannot halt an already stopped task + render json: {}, status: :bad_request + end end # we need do this to make the Foreman helpers working properly @@ -92,12 +97,6 @@ def resource_class private - def unlock_task(task) - task.state = :stopped - task.locks.destroy_all - task.save! - end - def respond_with_tasks(scope) @tasks = filter(scope, paginate: false).with_duration csv_response(@tasks, [:id, :action, :state, :result, 'started_at.in_time_zone', 'ended_at.in_time_zone', :duration, :username], ['Id', 'Action', 'State', 'Result', 'Started At', 'Ended At', 'Duration', 'User']) diff --git a/app/models/foreman_tasks/task/dynflow_task.rb b/app/models/foreman_tasks/task/dynflow_task.rb index 937e526f2..2f749d57f 100644 --- a/app/models/foreman_tasks/task/dynflow_task.rb +++ b/app/models/foreman_tasks/task/dynflow_task.rb @@ -251,6 +251,10 @@ def self.model_name superclass.model_name end + def halt + ::ForemanTasks.dynflow.world.halt(external_id) + end + private def string_to_time(zone, time) diff --git a/foreman-tasks.gemspec b/foreman-tasks.gemspec index b5d7b768a..bc49b98cf 100644 --- a/foreman-tasks.gemspec +++ b/foreman-tasks.gemspec @@ -26,7 +26,7 @@ same resource. It also optionally provides Dynflow infrastructure for using it f s.test_files = `git ls-files test`.split("\n") s.extra_rdoc_files = Dir['README*', 'LICENSE'] - s.add_dependency "dynflow", '>= 1.8.0' + s.add_dependency "dynflow", '>= 1.9.0' s.add_dependency 'fugit', '~> 1.8' s.add_dependency "get_process_mem" # for memory polling s.add_dependency "sinatra" # for Dynflow web console