Sha256: 61f4f07887d8404d1d0757e8bc2053212bbe8765ec9d24531c637674064b0ed8

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

class JobInvocationsController < ApplicationController
  include Foreman::Controller::AutoCompleteSearch

  def new
    @composer = JobInvocationComposer.new.compose_from_params(
      :host_ids => params[:host_ids],
      :targeting => {
        :targeting_type => Targeting::STATIC_TYPE,
        :bookmark_id => params[:bookmark_id]
      })
  end

  def rerun
    job_invocation = resource_base.find(params[:id])
    @composer = JobInvocationComposer.new.compose_from_invocation(job_invocation)

    if params[:failed_only]
      host_ids = job_invocation.failed_host_ids
      @composer.search_query = @composer.targeting.build_query_from_hosts(host_ids)
    end

    render :action => 'new'
  end

  def create
    @composer = JobInvocationComposer.new.compose_from_params(params)
    action = ::Actions::RemoteExecution::RunHostsJob
    if @composer.save
      job_invocation = @composer.job_invocation
      if job_invocation.trigger_mode == :future
        ForemanTasks.delay action,
                           job_invocation.delay_options,
                           job_invocation
      else
        ForemanTasks.async_task(action, job_invocation)
      end
      redirect_to job_invocation_path(job_invocation)
    else
      render :action => 'new'
    end
  end

  def show
    @job_invocation = resource_base.find(params[:id])
    @auto_refresh = @job_invocation.last_task.try(:pending?)
    hosts_base = @job_invocation.targeting.hosts.authorized(:view_hosts, Host)
    @hosts = hosts_base.search_for(params[:search], :order => params[:order] || 'name ASC').paginate(:page => params[:page])
  end

  def index
    @job_invocations = resource_base.search_for(params[:search]).paginate(:page => params[:page]).order('id DESC')
  end

  # refreshes the form
  def refresh
    @composer = JobInvocationComposer.new.compose_from_params(params)
  end

  private

  def action_permission
    case params[:action]
      when 'rerun'
        'create'
      else
        super
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_remote_execution-0.0.10 app/controllers/job_invocations_controller.rb
foreman_remote_execution-0.0.8 app/controllers/job_invocations_controller.rb