You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
598 B

  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