Move account deletion to Sidekiq worker, fixes #11

This commit is contained in:
pixeldesu 2015-07-15 01:44:35 +02:00
parent d3ebaf395f
commit 3a5dcbcd3b
4 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,10 @@
class User::RegistrationsController < Devise::RegistrationsController
def destroy
DeletionWorker.perform_async(resource.id)
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :destroyed if is_flashing_format?
yield resource if block_given?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end
end

View File

@ -0,0 +1,14 @@
class DeletionWorker
include Sidekiq::Worker
sidekiq_options queue: :deletion
# @param resource_id [Integer] user id passed from Devise
def perform(resource_id)
begin
User.find(resource_id).destroy!
rescue => e
Rails.logger.error "failed to delete user: #{e.message}"
end
end
end

View File

@ -46,7 +46,7 @@ Rails.application.routes.draw do
get '/settings/account' => 'devise/registrations#edit', as: :edit_user_registration
patch '/settings/account' => 'devise/registrations#update', as: :update_user_registration
put '/settings/account' => 'devise/registrations#update'
delete '/settings/account' => 'devise/registrations#destroy'
delete '/settings/account' => 'user/registrations#destroy'
end
match '/settings/profile', to: 'user#edit', via: 'get', as: :edit_user_profile

View File

@ -8,4 +8,5 @@ production:
:queues:
- share
- paperclip
- mailer
- mailer
- deletion