Commit 33279acb authored by Michael Kozono's avatar Michael Kozono

Backoff of retrying files missing on primary

parent 2d50b8a3
...@@ -62,10 +62,15 @@ module Geo ...@@ -62,10 +62,15 @@ module Geo
registry.success = mark_as_synced registry.success = mark_as_synced
registry.missing_on_primary = missing_on_primary registry.missing_on_primary = missing_on_primary
unless mark_as_synced retry_later = !registry.success || registry.missing_on_primary
if retry_later
# We don't limit the amount of retries # We don't limit the amount of retries
registry.retry_count = (registry.retry_count || 0) + 1 registry.retry_count = (registry.retry_count || 0) + 1
registry.retry_at = Time.now + delay(registry.retry_count).seconds registry.retry_at = Time.now + delay(registry.retry_count).seconds
else
registry.retry_count = 0
registry.retry_at = nil
end end
registry.save registry.save
......
...@@ -54,6 +54,13 @@ describe Geo::FileDownloadService do ...@@ -54,6 +54,13 @@ describe Geo::FileDownloadService do
execute! execute!
end end
it 'resets the retry fields' do
execute!
expect(registry.last.reload.retry_count).to eq(0)
expect(registry.last.retry_at).to be_nil
end
end end
context 'when the file fails to download' do context 'when the file fails to download' do
...@@ -81,6 +88,15 @@ describe Geo::FileDownloadService do ...@@ -81,6 +88,15 @@ describe Geo::FileDownloadService do
execute! execute!
end end
it 'sets a retry date and increments the retry count' do
Timecop.freeze do
execute!
expect(registry.last.reload.retry_count).to eq(1)
expect(registry.last.retry_at > Time.now).to be_truthy
end
end
end end
context 'when the file is not missing on the primary' do context 'when the file is not missing on the primary' do
...@@ -103,10 +119,12 @@ describe Geo::FileDownloadService do ...@@ -103,10 +119,12 @@ describe Geo::FileDownloadService do
end end
it 'sets a retry date and increments the retry count' do it 'sets a retry date and increments the retry count' do
execute! Timecop.freeze do
execute!
expect(registry.last.retry_count).to eq(1) expect(registry.last.reload.retry_count).to eq(1)
expect(registry.last.retry_at).to be_present expect(registry.last.retry_at > Time.now).to be_truthy
end
end end
end end
end end
...@@ -116,9 +134,9 @@ describe Geo::FileDownloadService do ...@@ -116,9 +134,9 @@ describe Geo::FileDownloadService do
context 'for a registered file that failed to sync' do context 'for a registered file that failed to sync' do
let!(:registry_entry) do let!(:registry_entry) do
if file_type == 'job_artifact' if file_type == 'job_artifact'
create(:geo_job_artifact_registry, success: false, artifact_id: file.id) create(:geo_job_artifact_registry, success: false, artifact_id: file.id, retry_count: 3, retry_at: 1.hour.ago)
else else
create(:geo_file_registry, file_type.to_sym, success: false, file_id: file.id) create(:geo_file_registry, file_type.to_sym, success: false, file_id: file.id, retry_count: 3, retry_at: 1.hour.ago)
end end
end end
...@@ -135,6 +153,13 @@ describe Geo::FileDownloadService do ...@@ -135,6 +153,13 @@ describe Geo::FileDownloadService do
expect { execute! }.to change { registry.synced.count }.by(1) expect { execute! }.to change { registry.synced.count }.by(1)
end end
it 'resets the retry fields' do
execute!
expect(registry_entry.reload.retry_count).to eq(0)
expect(registry_entry.retry_at).to be_nil
end
context 'when the file was marked as missing on the primary' do context 'when the file was marked as missing on the primary' do
before do before do
registry_entry.update_column(:missing_on_primary, true) registry_entry.update_column(:missing_on_primary, true)
...@@ -181,6 +206,15 @@ describe Geo::FileDownloadService do ...@@ -181,6 +206,15 @@ describe Geo::FileDownloadService do
execute! execute!
end end
it 'sets a retry date and increments the retry count' do
Timecop.freeze do
execute!
expect(registry_entry.reload.retry_count).to eq(4)
expect(registry_entry.retry_at > Time.now).to be_truthy
end
end
end end
context 'when the file is not missing on the primary' do context 'when the file is not missing on the primary' do
...@@ -202,12 +236,13 @@ describe Geo::FileDownloadService do ...@@ -202,12 +236,13 @@ describe Geo::FileDownloadService do
expect(registry_entry.reload.missing_on_primary).to be_falsey expect(registry_entry.reload.missing_on_primary).to be_falsey
end end
it 'changes the retry date and increments the retry count' do it 'sets a retry date and increments the retry count' do
expect { execute! }.to change { registry_entry.reload.retry_count }.from(nil).to(1) Timecop.freeze do
end execute!
it 'changes the retry date and increments the retry count' do expect(registry_entry.reload.retry_count).to eq(4)
expect { execute! }.to change { registry_entry.reload.retry_at } expect(registry_entry.retry_at > Time.now).to be_truthy
end
end end
end end
end end
......
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