summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-03-06 17:54:32 +0200
committerValery Sizov <vsv2711@gmail.com>2015-03-06 17:54:32 +0200
commit1c10220fa8bb519c97e6aea1af9620ac38c8a285 (patch)
treea799a2fd40422c2a2af9ecc2a63655a2a826e619
parent8452f94d44f8cc3ceb9b188e4a389a80e04f9eb4 (diff)
parent3137c0e409ed44d3623bebbd71ced3909af55c63 (diff)
downloadgitlab-ci-1c10220fa8bb519c97e6aea1af9620ac38c8a285.tar.gz
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ci
-rw-r--r--CHANGELOG2
-rw-r--r--app/controllers/admin/runners_controller.rb16
-rw-r--r--app/controllers/runners_controller.rb18
-rw-r--r--app/models/runner.rb15
-rw-r--r--app/views/admin/runners/_runner.html.haml11
-rw-r--r--app/views/admin/runners/index.html.haml5
-rw-r--r--app/views/runners/_runner.html.haml15
-rw-r--r--app/views/runners/edit.html.haml6
-rw-r--r--app/views/runners/index.html.haml12
-rw-r--r--config/routes.rb10
-rw-r--r--db/migrate/20150306131416_add_contacted_at_to_runner.rb5
-rw-r--r--db/migrate/20150306135341_add_active_to_runner.rb5
-rw-r--r--db/schema.rb4
-rw-r--r--lib/api/builds.rb4
-rw-r--r--lib/api/helpers.rb7
15 files changed, 122 insertions, 13 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 50ec9d5..33f4087 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,8 @@ v7.9.0
- Added api for project jobs
- 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 582407a..e1f685d 100644
--- a/app/models/runner.rb
+++ b/app/models/runner.rb
@@ -2,11 +2,12 @@
#
# Table name: runners
#
-# id :integer not null, primary key
-# token :string(255)
-# created_at :datetime
-# updated_at :datetime
-# description :string(255)
+# id :integer not null, primary key
+# token :string(255)
+# created_at :datetime
+# updated_at :datetime
+# contacted_at :datetime
+# description :string(255)
#
class Runner < ActiveRecord::Base
@@ -16,12 +17,14 @@ class Runner < ActiveRecord::Base
has_one :last_build, ->() { order('id DESC') }, class_name: 'Build'
- attr_accessible :token, :description, :tag_list
+ 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 2196a53..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
@@ -32,10 +34,17 @@
%span.label.label-primary
= tag
%td
- #{time_ago_in_words(runner.created_at)} ago
+ - if runner.contacted_at
+ #{time_ago_in_words(runner.contacted_at)} ago
+ - else
+ Never
%td
.pull-right
= link_to 'Edit', admin_runner_path(runner), class: 'btn btn-small'
&nbsp;
+ - 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 fd9849e..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
@@ -40,7 +43,7 @@
%th Projects
%th Builds
%th Tags
- %th Registered
+ %th Last contact
%th
= render @runners
diff --git a/app/views/runners/_runner.html.haml b/app/views/runners/_runner.html.haml
index 8401c65..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
@@ -14,11 +20,18 @@
%span.label.label-primary
= tag
%td
- #{time_ago_in_words(runner.created_at)} ago
+ - if runner.contacted_at
+ #{time_ago_in_words(runner.contacted_at)} ago
+ - else
+ Never
%td
.pull-right
= link_to 'Edit', edit_project_runner_path(@project, runner), class: 'btn btn-small'
&nbsp;
+ - 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 b71da50..6df2e8d 100644
--- a/app/views/runners/index.html.haml
+++ b/app/views/runners/index.html.haml
@@ -20,16 +20,26 @@
%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
%th Tags
- %th Registered
+ %th Last contact
%th
= render @runners
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/20150306131416_add_contacted_at_to_runner.rb b/db/migrate/20150306131416_add_contacted_at_to_runner.rb
new file mode 100644
index 0000000..b28f1ba
--- /dev/null
+++ b/db/migrate/20150306131416_add_contacted_at_to_runner.rb
@@ -0,0 +1,5 @@
+class AddContactedAtToRunner < ActiveRecord::Migration
+ def change
+ add_column :runners, :contacted_at, :datetime, null: true
+ 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 eafe0ee..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: 20150226001835) do
+ActiveRecord::Schema.define(version: 20150306135341) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -108,6 +108,8 @@ ActiveRecord::Schema.define(version: 20150226001835) do
t.datetime "created_at"
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 c4bcf88..bed20ac 100644
--- a/lib/api/builds.rb
+++ b/lib/api/builds.rb
@@ -11,7 +11,10 @@ module API
# POST /builds/register
post "register" do
authenticate_runner!
+ update_runner_last_contact
required_attributes! [:token]
+ not_found! unless current_runner.active?
+
build = RegisterBuildService.new.execute(current_runner)
if build
@@ -31,6 +34,7 @@ module API
# PUT /builds/:id
put ":id" do
authenticate_runner!
+ update_runner_last_contact
build = Build.where(runner_id: current_runner.id).running.find(params[:id])
build.update_attributes(trace: params[:trace]) if params[:trace]
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index fc19d76..58297a8 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -2,6 +2,7 @@ module API
module Helpers
PRIVATE_TOKEN_PARAM = :private_token
PRIVATE_TOKEN_HEADER = "HTTP_PRIVATE_TOKEN"
+ UPDATE_RUNNER_EVERY = 60
def current_user
@current_user ||= begin
@@ -33,6 +34,12 @@ module API
forbidden! unless project.valid_token?(params[:project_token])
end
+ def update_runner_last_contact
+ if current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= UPDATE_RUNNER_EVERY
+ current_runner.update_attributes(contacted_at: Time.now)
+ end
+ end
+
# Checks the occurrences of required attributes, each attribute must be present in the params hash
# or a Bad Request error is invoked.
#