summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Reigel <alexis.reigel.ext@siemens.com>2018-06-06 15:29:40 +0200
committerAlexis Reigel <alexis.reigel.ext@siemens.com>2018-08-20 17:12:15 +0200
commit00647b31b4741102451a2d785a43ef14bb818e24 (patch)
tree7d94580a6d4f83fd5684f66691cbd52b7d904c61
parent64d4f3b2a45a01e23f6c45515f4f0271ea6fd4a0 (diff)
downloadgitlab-ce-00647b31b4741102451a2d785a43ef14bb818e24.tar.gz
add offline scope to Ci::Runner
-rw-r--r--app/models/ci/runner.rb1
-rw-r--r--spec/models/ci/runner_spec.rb13
2 files changed, 13 insertions, 1 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index f41955f43e7..c0f632c2c9a 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -29,6 +29,7 @@ module Ci
scope :active, -> { where(active: true) }
scope :paused, -> { where(active: false) }
scope :online, -> { where('contacted_at > ?', contact_time_deadline) }
+ scope :offline, -> { where.not(id: online) }
scope :ordered, -> { order(id: :desc) }
# BACKWARD COMPATIBILITY: There are needed to maintain compatibility with `AVAILABLE_SCOPES` used by `lib/api/runners.rb`
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index 953af2c4710..f1d0ed15d29 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -223,7 +223,7 @@ describe Ci::Runner do
subject { described_class.online }
before do
- @runner1 = create(:ci_runner, :instance, contacted_at: 1.year.ago)
+ @runner1 = create(:ci_runner, :instance, contacted_at: 1.hour.ago)
@runner2 = create(:ci_runner, :instance, contacted_at: 1.second.ago)
end
@@ -300,6 +300,17 @@ describe Ci::Runner do
end
end
+ describe '.offline' do
+ subject { described_class.offline }
+
+ before do
+ @runner1 = create(:ci_runner, :instance, contacted_at: 1.hour.ago)
+ @runner2 = create(:ci_runner, :instance, contacted_at: 1.second.ago)
+ end
+
+ it { is_expected.to eq([@runner1])}
+ end
+
describe '#can_pick?' do
set(:pipeline) { create(:ci_pipeline) }
let(:build) { create(:ci_build, pipeline: pipeline) }