2019-04-04 23:07:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2019-10-02 12:01:53 +08:00
|
|
|
class EnsureS3UploadsExistence < ::Jobs::Scheduled
|
2019-04-04 23:07:44 +08:00
|
|
|
every 1.day
|
|
|
|
|
2020-07-29 08:49:45 +08:00
|
|
|
def perform(*args)
|
|
|
|
super
|
|
|
|
ensure
|
|
|
|
if @db_inventories
|
|
|
|
@db_inventories.values.each do |f|
|
|
|
|
f.close
|
|
|
|
f.unlink
|
2023-01-09 20:20:10 +08:00
|
|
|
end
|
2020-07-29 08:49:45 +08:00
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2019-04-04 23:07:44 +08:00
|
|
|
def execute(args)
|
2024-06-10 13:16:00 +08:00
|
|
|
return if (s3_inventory_bucket = SiteSetting.s3_inventory_bucket).blank?
|
2020-07-29 08:49:45 +08:00
|
|
|
|
|
|
|
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(
|
|
|
|
:upload,
|
2024-06-10 13:16:00 +08:00
|
|
|
s3_inventory_bucket:,
|
2020-07-29 08:49:45 +08:00
|
|
|
preloaded_inventory_file: preloaded_inventory_file,
|
|
|
|
preloaded_inventory_date: @inventory_date,
|
|
|
|
).backfill_etags_and_list_missing
|
|
|
|
else
|
2024-06-10 13:16:00 +08:00
|
|
|
S3Inventory.new(:upload, s3_inventory_bucket:).backfill_etags_and_list_missing
|
2020-07-29 08:49:45 +08:00
|
|
|
end
|
2019-04-04 23:07:44 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|