1
0

backup_worker.rb 598 B

1234567891011121314151617181920212223242526
  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. end
  11. end
  12. def perform(backup_id)
  13. backup = Backup.find(backup_id)
  14. user = backup.user
  15. BackupService.new.call(backup)
  16. user.backups.where.not(id: backup.id).destroy_all
  17. UserMailer.backup_ready(user, backup).deliver_later
  18. end
  19. end