discourse/app/jobs/scheduled/ensure_s3_uploads_existence.rb
Alan Guo Xiang Tan df16ab0758
FIX: S3Inventory to ignore files older than last backup restore date (#27166)
This commit updates `S3Inventory#files` to ignore S3 inventory files
which have a `last_modified` timestamp which are not at least 2 days
older than `BackupMetadata.last_restore_date` timestamp.

This check was previously only in `Jobs::EnsureS3UploadsExistence` but
`S3Inventory` can also be used via Rake tasks so this protection needs
to be in `S3Inventory` and not in the scheduled job.
2024-05-24 10:54:06 +08:00

51 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Jobs
class EnsureS3UploadsExistence < ::Jobs::Scheduled
every 1.day
def perform(*args)
super
ensure
if @db_inventories
@db_inventories.values.each do |f|
f.close
f.unlink
end
end
end
def s3_helper
Discourse.store.s3_helper
end
def prepare_for_all_sites
inventory = S3Inventory.new(s3_helper, :upload)
@db_inventories = inventory.prepare_for_all_sites
@inventory_date = inventory.inventory_date
end
def execute(args)
return if !SiteSetting.enable_s3_inventory
require "s3_inventory"
if !@db_inventories && Rails.configuration.multisite && GlobalSetting.use_s3?
prepare_for_all_sites
end
if @db_inventories &&
preloaded_inventory_file =
@db_inventories[RailsMultisite::ConnectionManagement.current_db]
S3Inventory.new(
s3_helper,
:upload,
preloaded_inventory_file: preloaded_inventory_file,
preloaded_inventory_date: @inventory_date,
).backfill_etags_and_list_missing
else
S3Inventory.new(s3_helper, :upload).backfill_etags_and_list_missing
end
end
end
end