backup_worker.rb 678 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class BackupWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'pull', backtrace: true, retry: 5, dead: false
  5. sidekiq_retries_exhausted do |msg|
  6. backup_id = msg['args'].first
  7. ActiveRecord::Base.connection_pool.with_connection do
  8. begin
  9. backup = Backup.find(backup_id)
  10. backup.destroy
  11. rescue ActiveRecord::RecordNotFound
  12. true
  13. end
  14. end
  15. end
  16. def perform(backup_id)
  17. backup = Backup.find(backup_id)
  18. user = backup.user
  19. BackupService.new.call(backup)
  20. user.backups.where.not(id: backup.id).destroy_all
  21. UserMailer.backup_ready(user, backup).deliver_later
  22. end
  23. end