BigW Consortium Gitlab

runners_controller.rb 1.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
class Admin::RunnersController < Admin::ApplicationController
  before_action :runner, except: :index

  def index
    @runners = Ci::Runner.order('id DESC')
    @runners = @runners.search(params[:search]) if params[:search].present?
    @runners = @runners.page(params[:page]).per(30)
    @active_runners_cnt = Ci::Runner.online.count
  end

  def show
12
    assign_builds_and_projects
13 14 15
  end

  def update
16
    if Ci::UpdateRunnerService.new(@runner).update(runner_params)
17 18 19 20 21 22 23
      respond_to do |format|
        format.js
        format.html { redirect_to admin_runner_path(@runner) }
      end
    else
      assign_builds_and_projects
      render 'show'
24 25 26 27 28 29
    end
  end

  def destroy
    @runner.destroy

30
    redirect_to admin_runners_path, status: 302
31 32 33
  end

  def resume
34
    if Ci::UpdateRunnerService.new(@runner).update(active: true)
35 36 37 38 39 40 41
      redirect_to admin_runners_path, notice: 'Runner was successfully updated.'
    else
      redirect_to admin_runners_path, alert: 'Runner was not updated.'
    end
  end

  def pause
42
    if Ci::UpdateRunnerService.new(@runner).update(active: false)
43 44 45 46 47 48 49 50 51 52 53 54 55
      redirect_to admin_runners_path, notice: 'Runner was successfully updated.'
    else
      redirect_to admin_runners_path, alert: 'Runner was not updated.'
    end
  end

  private

  def runner
    @runner ||= Ci::Runner.find(params[:id])
  end

  def runner_params
56
    params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
57
  end
58

59
  def assign_builds_and_projects
60 61 62 63 64 65 66 67 68 69
    @builds = runner.builds.order('id DESC').first(30)
    @projects =
      if params[:search].present?
        ::Project.search(params[:search])
      else
        Project.all
      end
    @projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any?
    @projects = @projects.page(params[:page]).per(30)
  end
70
end