Commit aa1aa227 authored by Mike Kozono's avatar Mike Kozono

Apply retry at time to needs_verification scope

Which is used in `needs_verification_count`. This scope must be kept in
sync with changes to `verification_failed_batch` and
`verification_pending_batch`.

Because `VerificationBatchWorker` (via `LimitedCapacity::Worker`) uses
`needs_verification_count` to determine whether it should reenqueue
itself, and how many jobs should be enqueued by `perform_with_capacity`.
parent 6ac29f89
...@@ -36,7 +36,7 @@ module Gitlab ...@@ -36,7 +36,7 @@ module Gitlab
scope :not_checksummed, -> { where(verification_checksum: nil) } scope :not_checksummed, -> { where(verification_checksum: nil) }
scope :verification_timed_out, -> { verification_started.where("verification_started_at < ?", VERIFICATION_TIMEOUT.ago) } scope :verification_timed_out, -> { verification_started.where("verification_started_at < ?", VERIFICATION_TIMEOUT.ago) }
scope :retry_due, -> { where(arel_table[:verification_retry_at].eq(nil).or(arel_table[:verification_retry_at].lt(Time.current))) } scope :retry_due, -> { where(arel_table[:verification_retry_at].eq(nil).or(arel_table[:verification_retry_at].lt(Time.current))) }
scope :needs_verification, -> { with_verification_state(:verification_pending, :verification_failed) } scope :needs_verification, -> { with_verification_state(:verification_pending).or(with_verification_state(:verification_failed).retry_due) }
# rubocop:enable CodeReuse/ActiveRecord # rubocop:enable CodeReuse/ActiveRecord
state_machine :verification_state, initial: :verification_pending do state_machine :verification_state, initial: :verification_pending do
......
...@@ -145,6 +145,30 @@ RSpec.describe Gitlab::Geo::VerificationState do ...@@ -145,6 +145,30 @@ RSpec.describe Gitlab::Geo::VerificationState do
end end
end end
describe '.needs_verification' do
it 'includes verification_pending' do
subject.save!
expect(subject.class.needs_verification).to include(subject)
end
it 'includes verification_failed and retry_due' do
subject.verification_started
subject.verification_failed_with_message!('foo')
subject.update!(verification_retry_at: 1.minute.ago)
expect(subject.class.needs_verification).to include(subject)
end
it 'excludes verification_failed with future verification_retry_at' do
subject.verification_started
subject.verification_failed_with_message!('foo')
subject.update!(verification_retry_at: 1.minute.from_now)
expect(subject.class.needs_verification).not_to include(subject)
end
end
describe '.fail_verification_timeouts' do describe '.fail_verification_timeouts' do
before do before do
subject.verification_started! subject.verification_started!
......
...@@ -86,12 +86,22 @@ RSpec.shared_examples 'a Geo verifiable registry' do ...@@ -86,12 +86,22 @@ RSpec.shared_examples 'a Geo verifiable registry' do
subject.save! subject.save!
end end
it 'returns the number of rows which are synced and (pending or failed) verification' do it 'returns the number of rows which are synced and pending verification' do
create(registry_class_factory, :synced, verification_state: verification_state_value(:verification_failed), verification_failure: 'foo') # rubocop:disable Rails/SaveBang expect(described_class.needs_verification_count(limit: 3)).to eq(1)
end
it 'includes rows which are synced and failed verification and are due for retry' do
create(registry_class_factory, :synced, verification_state: verification_state_value(:verification_failed), verification_failure: 'foo', verification_retry_at: 1.minute.ago) # rubocop:disable Rails/SaveBang
expect(described_class.needs_verification_count(limit: 3)).to eq(2) expect(described_class.needs_verification_count(limit: 3)).to eq(2)
end end
it 'excludes rows which are synced and failed verification and have a future retry time' do
create(registry_class_factory, :synced, verification_state: verification_state_value(:verification_failed), verification_failure: 'foo', verification_retry_at: 1.minute.from_now) # rubocop:disable Rails/SaveBang
expect(described_class.needs_verification_count(limit: 3)).to eq(1)
end
it 'excludes rows which are not synced or are not (pending or failed) verification' do it 'excludes rows which are not synced or are not (pending or failed) verification' do
# rubocop:disable Rails/SaveBang # rubocop:disable Rails/SaveBang
create(registry_class_factory, verification_state: verification_state_value(:verification_pending)) create(registry_class_factory, verification_state: verification_state_value(:verification_pending))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment