Commit 046ad504 authored by Valery Sizov's avatar Valery Sizov

Geo: Add specs for error handling

parent e9478858
class Geo::FileRegistry < Geo::BaseRegistry
scope :failed, -> { where(success: false) }
scope :synced, -> { where(success: true) }
scope :to_be_retried, -> { where('retry_at < ?', Time.now) }
scope :to_be_retried, -> { where('retry_at is NULL OR retry_at < ?', Time.now) }
end
......@@ -4,7 +4,6 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
validates :project, presence: true, uniqueness: true
scope :dirty, -> { where(arel_table[:resync_repository].eq(true).or(arel_table[:resync_wiki].eq(true))) }
scope :to_be_retried, -> { where(arel_table[:repository_retry_at].lt(Time.now).or(arel_table[:wiki_retry_at].lt(Time.now))) }
def self.failed
repository_sync_failed = arel_table[:last_repository_synced_at].not_eq(nil)
......@@ -16,6 +15,15 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
where(repository_sync_failed.or(wiki_sync_failed))
end
def self.to_be_retried
where(
arel_table[:repository_retry_at].lt(Time.now)
.or(arel_table[:wiki_retry_at].lt(Time.now))
.or(arel_table[:wiki_retry_at].eq(nil))
.or(arel_table[:wiki_retry_at].eq(nil))
)
end
def self.synced
where.not(last_repository_synced_at: nil, last_repository_successful_sync_at: nil)
.where(resync_repository: false, resync_wiki: false)
......
......@@ -63,17 +63,17 @@ module Geo
private
def retry_count
registry.public_send("#{type}_retry_count") || 0
registry.public_send("#{type}_retry_count") || 0 # rubocop:disable GitlabSecurity/PublicSend
end
def should_be_retried?
return false if registry.public_send("force_to_redownload_#{type}")
return false if registry.public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend
retry_count <= RETRY_BEFORE_REDOWNLOAD
end
def should_be_redownloaded?
return true if registry.public_send("force_to_redownload_#{type}")
return true if registry.public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend
(RETRY_BEFORE_REDOWNLOAD..RETRY_LIMIT) === retry_count
end
......
module Delay
# Progressive backoff. It's copied from Sidekiq as is
def delay(retry_count = 0)
(retry_count ** 4) + 15 + (rand(30) * (retry_count + 1))
(retry_count**4) + 15 + (rand(30) * (retry_count + 1))
end
end
......@@ -8,6 +8,7 @@ shared_examples 'geo base sync execution' do
end
it 'executes the synchronization' do
subject.class.type ||= :wiki
expect(subject).to receive(:sync_repository)
subject.execute
......
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