| 
									
										
										
										
											2018-02-21 23:21:32 +01:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BackupWorker | 
					
						
							|  |  |  |   include Sidekiq::Worker | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 08:15:24 +01:00
										 |  |  |   sidekiq_options queue: 'pull', backtrace: true, retry: 5, dead: false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sidekiq_retries_exhausted do |msg| | 
					
						
							|  |  |  |     backup_id = msg['args'].first | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ActiveRecord::Base.connection_pool.with_connection do | 
					
						
							| 
									
										
										
										
											2020-03-08 23:56:18 +01:00
										 |  |  |       begin | 
					
						
							|  |  |  |         backup = Backup.find(backup_id) | 
					
						
							|  |  |  |         backup.destroy | 
					
						
							|  |  |  |       rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |         true | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-03-13 08:15:24 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-02-21 23:21:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def perform(backup_id) | 
					
						
							|  |  |  |     backup = Backup.find(backup_id) | 
					
						
							|  |  |  |     user   = backup.user | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BackupService.new.call(backup) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     user.backups.where.not(id: backup.id).destroy_all | 
					
						
							|  |  |  |     UserMailer.backup_ready(user, backup).deliver_later | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |