backup_worker.rb 648 B

12345678910111213141516171819202122232425262728
  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. backup = Backup.find(backup_id)
  9. backup.destroy
  10. rescue ActiveRecord::RecordNotFound
  11. true
  12. end
  13. end
  14. def perform(backup_id)
  15. backup = Backup.find(backup_id)
  16. user = backup.user
  17. BackupService.new.call(backup)
  18. user.backups.where.not(id: backup.id).destroy_all
  19. UserMailer.backup_ready(user, backup).deliver_later
  20. end
  21. end