diff options
-rw-r--r-- | app/models/ci/runner.rb | 1 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 13 |
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) } |