Skip to content

A platform for community discussion. Free, open, simple.

FIX: run the rake task only for uploads created before a day from inventory date

Vinoth Kannanb5fbd7385f8c
diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb
index 05096f0a302..8acb9b2051d 100644
--- a/lib/s3_inventory.rb
+++ b/lib/s3_inventory.rb
@@ -5,7 +5,7 @@ require "csv"
class S3Inventory
- attr_reader :inventory_id, :model, :last_modified
+ attr_reader :inventory_id, :model, :inventory_date
CSV_KEY_INDEX ||= 1
CSV_ETAG_INDEX ||= 2
@@ -53,7 +53,7 @@ class S3Inventory
end
end
- uploads = (model == Upload) ? model.where("created_at < ?", last_modified) : model
+ uploads = (model == Upload) ? model.where("created_at < ?", inventory_date) : model
missing_uploads = uploads.joins("LEFT JOIN #{table_name} ON #{table_name}.etag = #{model.table_name}.etag").where("#{table_name}.etag is NULL")
if (missing_count = missing_uploads.count) > 0
@@ -129,7 +129,7 @@ class S3Inventory
symlink_file = unsorted_files.sort_by { |file| -file.last_modified.to_i }.first
return [] if symlink_file.blank?
- @last_modified = symlink_file.last_modified
+ @inventory_date = symlink_file.last_modified - 1.day
log "Downloading symlink file to tmp directory..."
failure_message = "Failed to download symlink file to tmp directory."
filename = File.join(tmp_directory, File.basename(symlink_file.key))
diff --git a/spec/components/s3_inventory_spec.rb b/spec/components/s3_inventory_spec.rb
index 617101eef4f..26e77725819 100644
--- a/spec/components/s3_inventory_spec.rb
+++ b/spec/components/s3_inventory_spec.rb
@@ -66,8 +66,8 @@ describe "S3Inventory" do
inventory.expects(:download_inventory_files_to_tmp_directory)
inventory.expects(:decompress_inventory_files)
- inventory.expects(:files).returns([{ key: "Key", filename: "#{csv_filename}.gz" }]).at_least(1)
- inventory.expects(:last_modified).returns(Time.now)
+ inventory.expects(:files).returns([{ key: "Key", filename: "#{csv_filename}.gz" }]).times(2)
+ inventory.expects(:inventory_date).returns(Time.now)
output = capture_stdout do
inventory.list_missing
@@ -81,7 +81,7 @@ describe "S3Inventory" do
inventory.expects(:download_inventory_files_to_tmp_directory)
inventory.expects(:decompress_inventory_files)
- inventory.expects(:files).returns([{ key: "Key", filename: "#{csv_filename}.gz" }]).at_least(1)
+ inventory.expects(:files).returns([{ key: "Key", filename: "#{csv_filename}.gz" }]).times(2)
output = capture_stdout do
expect { inventory.list_missing(backfill_etags: true) }.to change { Upload.where(etag: nil).count }.by(-1)