Sha256: 34694975caf5166d0678c86e5d047e65ae1dc9e7730c1c8c930212309cc956ff

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 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 cancel_step
      task = find_task
      flash[:notice] = _("Trying to cancel step %s") % params[:step_id]
      ForemanTasks.dynflow.world.event(task.external_id, params[:step_id].to_i, ::Dynflow::Action::Cancellable::Cancel)
      redirect_to foreman_tasks_task_path(task)
    end

    def resume
      task = find_task
      if task.resumable?
        ForemanTasks.dynflow.world.execute(task.execution_plan.id)
        flash[:notice] = _('The execution was resumed.')
      else
        flash[:warning] = _('The execution has to be resumable.')
      end
      redirect_to foreman_tasks_task_path(task)
    end

    def unlock
      task = find_task
      if task.paused?
        task.state = :stopped
        task.save!
        flash[:notice] = _('The task resrouces were unlocked.')
      else
        flash[:warning] =  _('The execution has to be paused.')
      end
      redirect_to foreman_tasks_task_path(task)
    end

    def force_unlock
      task       = find_task
      task.state = :stopped
      task.save!
      flash[:notice] = _('The task resources were unlocked 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 find_task
      ForemanTasks::Task::DynflowTask.find(params[:id])
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman-tasks-0.6.2 app/controllers/foreman_tasks/tasks_controller.rb
foreman-tasks-0.6.1 app/controllers/foreman_tasks/tasks_controller.rb
foreman-tasks-0.6.0 app/controllers/foreman_tasks/tasks_controller.rb