diff options
| author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-10-12 21:12:31 +0200 |
|---|---|---|
| committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-10-14 17:29:18 +0200 |
| commit | 7af4f5215e28927830cbc74d383cdfeb9e4ef587 (patch) | |
| tree | 1a318a590e96153ebb1a843538dd70279e098c2a /app/models/ci | |
| parent | 2d0fcb4de23ab368e2e030b3cf7f6b1705ef676f (diff) | |
| download | gitlab-ce-7af4f5215e28927830cbc74d383cdfeb9e4ef587.tar.gz | |
Show warning if build doesn't have runners with specified tags or runners didn't connect recently
Slightly refactor runner status detection: moving it to Runner class
Signed-off-by: Kamil Trzcinski <ayufan@ayufan.eu>
Diffstat (limited to 'app/models/ci')
| -rw-r--r-- | app/models/ci/build.rb | 12 | ||||
| -rw-r--r-- | app/models/ci/project.rb | 6 | ||||
| -rw-r--r-- | app/models/ci/runner.rb | 17 |
3 files changed, 32 insertions, 3 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index cfafbf6786e..2c7cad46b00 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -231,6 +231,18 @@ module Ci end end + def can_be_served?(runner) + (tag_list - runner.tag_list).empty? + end + + def any_runners_online? + project.any_runners? { |runner| runner.active? && runner.online? && can_be_served?(runner) } + end + + def show_warning? + pending? && !any_runners_online? + end + private def yaml_variables diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index 88ba933a434..ef28353a30c 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -115,12 +115,12 @@ module Ci web_url end - def any_runners? - if runners.active.any? + def any_runners?(&block) + if runners.active.any?(&block) return true end - shared_runners_enabled && Ci::Runner.shared.active.any? + shared_runners_enabled && Ci::Runner.shared.active.any?(&block) end def set_default_values diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 6838ccfaaab..02a3e9db1fa 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -20,6 +20,8 @@ module Ci class Runner < ActiveRecord::Base extend Ci::Model + + LAST_CONTACT_TIME = 5.minutes.ago has_many :builds, class_name: 'Ci::Build' has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject' @@ -33,6 +35,7 @@ module Ci scope :shared, ->() { where(is_shared: true) } scope :active, ->() { where(active: true) } scope :paused, ->() { where(active: false) } + scope :online, ->() { where('contacted_at > ?', LAST_CONTACT_TIME) } acts_as_taggable @@ -65,6 +68,20 @@ module Ci is_shared end + def online? + contacted_at && contacted_at > LAST_CONTACT_TIME + end + + def status + if contacted_at.nil? + :not_connected + elsif active? + online? ? :online : :offline + else + :paused + end + end + def belongs_to_one_project? runner_projects.count == 1 end |
