summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-03-06 14:29:11 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2015-03-06 14:42:04 +0100
commit0c71a4c41465cd620e163e081f31567ce59de766 (patch)
tree5c7a14a7a405a06f571391911eb124e4e958c89a
parent1ba0a907f77f9b3693485e3c7080c8de6fdf1b92 (diff)
downloadgitlab-ci-0c71a4c41465cd620e163e081f31567ce59de766.tar.gz
Added runner last contact
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/runner.rb13
-rw-r--r--app/views/admin/runners/_runner.html.haml5
-rw-r--r--app/views/admin/runners/index.html.haml2
-rw-r--r--app/views/runners/_runner.html.haml5
-rw-r--r--app/views/runners/index.html.haml2
-rw-r--r--db/migrate/20150306131416_add_contacted_at_to_runner.rb5
-rw-r--r--db/schema.rb3
-rw-r--r--lib/api/builds.rb2
-rw-r--r--lib/api/helpers.rb7
10 files changed, 34 insertions, 11 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 50ec9d5..c152cab 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,7 @@ 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)
v7.8.2
- Fix the broken build failed email
diff --git a/app/models/runner.rb b/app/models/runner.rb
index 582407a..f22dc2e 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,7 +17,7 @@ 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
before_validation :set_default_values
diff --git a/app/views/admin/runners/_runner.html.haml b/app/views/admin/runners/_runner.html.haml
index 2196a53..d0b9593 100644
--- a/app/views/admin/runners/_runner.html.haml
+++ b/app/views/admin/runners/_runner.html.haml
@@ -32,7 +32,10 @@
%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'
diff --git a/app/views/admin/runners/index.html.haml b/app/views/admin/runners/index.html.haml
index fd9849e..7163f18 100644
--- a/app/views/admin/runners/index.html.haml
+++ b/app/views/admin/runners/index.html.haml
@@ -40,7 +40,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..275a0f8 100644
--- a/app/views/runners/_runner.html.haml
+++ b/app/views/runners/_runner.html.haml
@@ -14,7 +14,10 @@
%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'
diff --git a/app/views/runners/index.html.haml b/app/views/runners/index.html.haml
index b71da50..860cc6a 100644
--- a/app/views/runners/index.html.haml
+++ b/app/views/runners/index.html.haml
@@ -29,7 +29,7 @@
%th Description
%th Last build
%th Tags
- %th Registered
+ %th Last contact
%th
= render @runners
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/schema.rb b/db/schema.rb
index eafe0ee..a1aa0e7 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: 20150306131416) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -108,6 +108,7 @@ ActiveRecord::Schema.define(version: 20150226001835) do
t.datetime "created_at"
t.datetime "updated_at"
t.string "description"
+ t.datetime "contacted_at"
end
create_table "services", force: true do |t|
diff --git a/lib/api/builds.rb b/lib/api/builds.rb
index c4bcf88..e33491a 100644
--- a/lib/api/builds.rb
+++ b/lib/api/builds.rb
@@ -11,6 +11,7 @@ module API
# POST /builds/register
post "register" do
authenticate_runner!
+ update_runner_last_contact
required_attributes! [:token]
build = RegisterBuildService.new.execute(current_runner)
@@ -31,6 +32,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.
#