2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
class Admin::RunnersController < Admin::ApplicationController
|
2019-07-07 11:18:12 +05:30
|
|
|
before_action :runner, except: [:index, :tag_list]
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
def index
|
2018-12-05 23:21:45 +05:30
|
|
|
finder = Admin::RunnersFinder.new(params: params)
|
|
|
|
@runners = finder.execute
|
|
|
|
@active_runners_count = Ci::Runner.online.count
|
|
|
|
@sort = finder.sort_key
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-06-02 11:05:42 +05:30
|
|
|
assign_builds_and_projects
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-08-17 22:00:37 +05:30
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(runner_params)
|
2016-06-02 11:05:42 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.html { redirect_to admin_runner_path(@runner) }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
assign_builds_and_projects
|
|
|
|
render 'show'
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@runner.destroy
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
redirect_to admin_runners_path, status: :found
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def resume
|
2017-08-17 22:00:37 +05:30
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: true)
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
|
2015-12-23 02:04:40 +05:30
|
|
|
else
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_runners_path, alert: _('Runner was not updated.')
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
2017-08-17 22:00:37 +05:30
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: false)
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_runners_path, notice: _('Runner was successfully updated.')
|
2015-12-23 02:04:40 +05:30
|
|
|
else
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_runners_path, alert: _('Runner was not updated.')
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def tag_list
|
|
|
|
tags = Autocomplete::ActsAsTaggableOn::TagsFinder.new(params: params).execute
|
|
|
|
|
|
|
|
render json: ActsAsTaggableOn::TagSerializer.new.represent(tags)
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def runner
|
|
|
|
@runner ||= Ci::Runner.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def runner_params
|
2020-04-22 19:07:51 +05:30
|
|
|
params.require(:runner).permit(permitted_attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_attrs
|
|
|
|
if Gitlab.com?
|
|
|
|
Ci::Runner::FORM_EDITABLE + Ci::Runner::MINUTES_COST_FACTOR_FIELDS
|
|
|
|
else
|
|
|
|
Ci::Runner::FORM_EDITABLE
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-06-02 11:05:42 +05:30
|
|
|
def assign_builds_and_projects
|
2020-03-13 15:44:24 +05:30
|
|
|
@builds = runner.builds.order('id DESC').preload_project_and_pipeline_project.first(30)
|
2016-06-02 11:05:42 +05:30
|
|
|
@projects =
|
|
|
|
if params[:search].present?
|
|
|
|
::Project.search(params[:search])
|
|
|
|
else
|
|
|
|
Project.all
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any?
|
2020-03-13 15:44:24 +05:30
|
|
|
@projects = @projects.inc_routes
|
|
|
|
@projects = @projects.page(params[:page]).per(30).without_count
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|