Class: Jobs::SyncAclsForUploads
- Defined in:
- app/jobs/regular/sync_acls_for_uploads.rb
Overview
Sometimes we need to update a lot of ACLs on S3 (such as when secure uploads is enabled), and since it takes ~1s per upload to update the ACL, this is best spread out over many jobs instead of having to do the whole thing serially.
Instance Method Summary collapse
Methods inherited from Base
acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately
Instance Method Details
#execute(args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/jobs/regular/sync_acls_for_uploads.rb', line 8 def execute(args) return if !Discourse.store.external? return if !args.key?(:upload_ids) # TODO (martin) Change the logging here to debug after acl_stale implemented. # # Note...these log messages are set to warn to ensure this is working # as intended in initial production trials, this will be set to debug # after an acl_stale column is added to uploads. time = Benchmark.measure do Rails.logger.warn("Syncing ACL for upload ids: #{args[:upload_ids].join(", ")}") Upload .includes(:optimized_images) .where(id: args[:upload_ids]) .find_in_batches do |uploads| uploads.each do |upload| begin Discourse.store.update_upload_ACL(upload, optimized_images_preloaded: true) rescue => err Discourse.warn_exception( err, message: "Failed to update upload ACL", env: { upload_id: upload.id, filename: upload.original_filename, }, ) end end end Rails.logger.warn( "Completed syncing ACL for upload ids in #{time.to_s}. IDs: #{args[:upload_ids].join(", ")}", ) end end |