Sha256: 30a0f27ab31b59347411e030f7f2b50db194fed5e5c80ecf11b240fe86f4c491

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

module ForemanTasks
  class TasksController < ::ApplicationController
    include Foreman::Controller::AutoCompleteSearch

    def show
      @task = Task.find(params[:id])
    end

    def index
      params[:order] ||= 'started_at DESC'
      @tasks         = Task.
          search_for(params[:search], :order => params[:order]).
          paginate(:page => params[:page])
    end

    def resume
      paused_task_action _('The execution was resumed.') do |task|
        ForemanTasks.dynflow.world.execute(task.execution_plan.id)
      end
    end

    def stop
      paused_task_action _('The execution was stopped.') do |task|
        # FIXME also stop dynflow execution plan
        task.state = :stopped
        task.save!
      end
    end

    def force_stop
      task       = find_task
      task.state = :stopped
      task.save!
      flash[:notice] = _('The task was stopped with force.')
      redirect_to foreman_tasks_task_path(task)
    end

    # we need do this to make the Foreman helpers working properly
    def controller_name
      'foreman_tasks_tasks'
    end

    private

    def paused_task_action(success_message)
      task = find_task
      if task.state != 'paused'
        flash[:warning] = _('The execution has to be paused.')
      else
        yield task
        flash[:notice] = success_message
      end

      redirect_to foreman_tasks_task_path(task)
    end

    def find_task
      ForemanTasks::Task::DynflowTask.find(params[:id])
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman-tasks-0.5.7 app/controllers/foreman_tasks/tasks_controller.rb
foreman-tasks-0.5.6 app/controllers/foreman_tasks/tasks_controller.rb
foreman-tasks-0.5.5 app/controllers/foreman_tasks/tasks_controller.rb
foreman-tasks-0.5.4 app/controllers/foreman_tasks/tasks_controller.rb