diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-03-06 16:34:52 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-03-06 16:35:30 +0100 |
commit | b908541cb3eee4bcafa521cbe0a4645bd6182f20 (patch) | |
tree | cf2e37254c010f1b1abbb6d53391801632f750a3 | |
parent | 0c71a4c41465cd620e163e081f31567ce59de766 (diff) | |
download | gitlab-ci-b908541cb3eee4bcafa521cbe0a4645bd6182f20.tar.gz |
Allow to pause runners - when paused runner will not receive any new build
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/admin/runners_controller.rb | 16 | ||||
-rw-r--r-- | app/controllers/runners_controller.rb | 18 | ||||
-rw-r--r-- | app/models/runner.rb | 4 | ||||
-rw-r--r-- | app/views/admin/runners/_runner.html.haml | 6 | ||||
-rw-r--r-- | app/views/admin/runners/index.html.haml | 3 | ||||
-rw-r--r-- | app/views/runners/_runner.html.haml | 10 | ||||
-rw-r--r-- | app/views/runners/edit.html.haml | 6 | ||||
-rw-r--r-- | app/views/runners/index.html.haml | 10 | ||||
-rw-r--r-- | config/routes.rb | 10 | ||||
-rw-r--r-- | db/migrate/20150306135341_add_active_to_runner.rb | 5 | ||||
-rw-r--r-- | db/schema.rb | 3 | ||||
-rw-r--r-- | lib/api/builds.rb | 2 |
13 files changed, 90 insertions, 4 deletions
@@ -7,6 +7,7 @@ v7.9.0 - Implementation of deploy jobs after all parallel jobs(tests). - Add scroll up/down buttons for better mobile experience with large build traces - Add runner last contact (Kamil Trzciński) + - Allow to pause runners - when paused runner will not receive any new build (Kamil Trzciński) v7.8.2 - Fix the broken build failed email diff --git a/app/controllers/admin/runners_controller.rb b/app/controllers/admin/runners_controller.rb index ad6c610..a6ef86e 100644 --- a/app/controllers/admin/runners_controller.rb +++ b/app/controllers/admin/runners_controller.rb @@ -27,6 +27,22 @@ class Admin::RunnersController < Admin::ApplicationController redirect_to admin_runners_path end + def resume + if @runner.update_attributes(active: true) + 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 + if @runner.update_attributes(active: false) + redirect_to admin_runners_path, notice: 'Runner was successfully updated.' + else + redirect_to admin_runners_path, alert: 'Runner was not updated.' + end + end + def assign_all Project.unassigned(@runner).all.each do |project| @runner.assign_to(project, current_user) diff --git a/app/controllers/runners_controller.rb b/app/controllers/runners_controller.rb index 395d376..4780069 100644 --- a/app/controllers/runners_controller.rb +++ b/app/controllers/runners_controller.rb @@ -1,7 +1,7 @@ class RunnersController < ApplicationController before_filter :authenticate_user! before_filter :project - before_filter :set_runner, only: [:edit, :update, :destroy] + before_filter :set_runner, only: [:edit, :update, :destroy, :pause, :resume] before_filter :authorize_access_project! before_filter :authorize_manage_project! @@ -33,6 +33,22 @@ class RunnersController < ApplicationController redirect_to project_runners_path(@project) end + def resume + if @runner.update_attributes(active: true) + redirect_to project_runners_path(@project, @runner), notice: 'Runner was successfully updated.' + else + redirect_to project_runners_path(@project, @runner), alert: 'Runner was not updated.' + end + end + + def pause + if @runner.update_attributes(active: false) + redirect_to project_runners_path(@project, @runner), notice: 'Runner was successfully updated.' + else + redirect_to project_runners_path(@project, @runner), alert: 'Runner was not updated.' + end + end + protected def project diff --git a/app/models/runner.rb b/app/models/runner.rb index f22dc2e..e1f685d 100644 --- a/app/models/runner.rb +++ b/app/models/runner.rb @@ -17,12 +17,14 @@ class Runner < ActiveRecord::Base has_one :last_build, ->() { order('id DESC') }, class_name: 'Build' - attr_accessible :token, :description, :tag_list, :contacted_at + attr_accessible :token, :description, :tag_list, :contacted_at, :active before_validation :set_default_values scope :specific, ->() { where(id: RunnerProject.select(:runner_id)) } scope :shared, ->() { where.not(id: RunnerProject.select(:runner_id)) } + scope :active, ->() { where(active: true) } + scope :paused, ->() { where(active: false) } acts_as_taggable diff --git a/app/views/admin/runners/_runner.html.haml b/app/views/admin/runners/_runner.html.haml index d0b9593..5340830 100644 --- a/app/views/admin/runners/_runner.html.haml +++ b/app/views/admin/runners/_runner.html.haml @@ -6,6 +6,8 @@ %span.label.label-success shared - else %span.label.label-info specific + - unless runner.active? + %span.label.label-danger paused %td = link_to admin_runner_path(runner) do @@ -40,5 +42,9 @@ .pull-right = link_to 'Edit', admin_runner_path(runner), class: 'btn btn-small' + - if runner.active? + = link_to 'Pause', [:pause, :admin, runner], data: { confirm: "Are you sure?" }, method: :get, class: 'btn btn-danger btn-small' + - else + = link_to 'Resume', [:resume, :admin, runner], method: :get, class: 'btn btn-success btn-small' = link_to 'Remove', [:admin, runner], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small' diff --git a/app/views/admin/runners/index.html.haml b/app/views/admin/runners/index.html.haml index 7163f18..abbcf8f 100644 --- a/app/views/admin/runners/index.html.haml +++ b/app/views/admin/runners/index.html.haml @@ -27,6 +27,9 @@ %li %span.label.label-info specific \- run builds from assigned projects + %li + %span.label.label-danger paused + \- runner will not receive any new build diff --git a/app/views/runners/_runner.html.haml b/app/views/runners/_runner.html.haml index 275a0f8..1c75058 100644 --- a/app/views/runners/_runner.html.haml +++ b/app/views/runners/_runner.html.haml @@ -2,6 +2,12 @@ %td %strong ##{runner.id} %td + - if runner.active? + %span.label.label-success active + - else + %span.label.label-danger paused + + %td = runner.short_sha %td .runner-description @@ -22,6 +28,10 @@ .pull-right = link_to 'Edit', edit_project_runner_path(@project, runner), class: 'btn btn-small' + - if runner.active? + = link_to 'Pause', [:pause, @project, runner], data: { confirm: "Are you sure?" }, method: :get, class: 'btn btn-danger btn-small' + - else + = link_to 'Resume', [:resume, @project, runner], method: :get, class: 'btn btn-success btn-small' - if runner.only_for?(@project) = link_to 'Remove', [@project, runner], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small' diff --git a/app/views/runners/edit.html.haml b/app/views/runners/edit.html.haml index e70a283..fd0e7d7 100644 --- a/app/views/runners/edit.html.haml +++ b/app/views/runners/edit.html.haml @@ -2,6 +2,12 @@ %hr = form_for [@project, @runner], html: { class: 'form-horizontal' } do |f| .form-group + = label :active, "Active", class: 'control-label' + .col-sm-10 + .checkbox + = f.check_box :active + %span.light Paused runners don't accept new jobs + .form-group = label_tag :token, class: 'control-label' do Token .col-sm-10 diff --git a/app/views/runners/index.html.haml b/app/views/runners/index.html.haml index 860cc6a..6df2e8d 100644 --- a/app/views/runners/index.html.haml +++ b/app/views/runners/index.html.haml @@ -20,11 +20,21 @@ %li Start runner! + %h4 Each runner can be in one of the following states: + %div + %ul + %li + %span.label.label-success active + \- runner is active and can process any new build + %li + %span.label.label-danger paused + \- runner is paused and will not receive any new build %table.table %thead %tr %th ID + %th Type %th Runner token %th Description %th Last build diff --git a/config/routes.rb b/config/routes.rb index 62e0665..f666482 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,7 +48,13 @@ Rails.application.routes.draw do end end - resources :runners, only: [:index, :edit, :update, :destroy] + resources :runners, only: [:index, :edit, :update, :destroy] do + member do + get :resume + get :pause + end + end + resources :jobs, only: [:index] do collection do get :deploy_jobs @@ -65,6 +71,8 @@ Rails.application.routes.draw do resources :runners, only: [:index, :show, :update, :destroy] do member do put :assign_all + get :resume + get :pause end end diff --git a/db/migrate/20150306135341_add_active_to_runner.rb b/db/migrate/20150306135341_add_active_to_runner.rb new file mode 100644 index 0000000..2b9a3dc --- /dev/null +++ b/db/migrate/20150306135341_add_active_to_runner.rb @@ -0,0 +1,5 @@ +class AddActiveToRunner < ActiveRecord::Migration + def change + add_column :runners, :active, :boolean, null: false, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index a1aa0e7..804984c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150306131416) do +ActiveRecord::Schema.define(version: 20150306135341) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -109,6 +109,7 @@ ActiveRecord::Schema.define(version: 20150306131416) do t.datetime "updated_at" t.string "description" t.datetime "contacted_at" + t.boolean "active", default: true, null: false end create_table "services", force: true do |t| diff --git a/lib/api/builds.rb b/lib/api/builds.rb index e33491a..bed20ac 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -13,6 +13,8 @@ module API authenticate_runner! update_runner_last_contact required_attributes! [:token] + not_found! unless current_runner.active? + build = RegisterBuildService.new.execute(current_runner) if build |