docbrown/app/workers/users/delete_worker.rb

27 lines
1,001 B
Ruby

module Users
class DeleteWorker
include Sidekiq::Job
sidekiq_options queue: :high_priority, retry: 10
def perform(user_id, admin_delete = false) # rubocop:disable Style/OptionalBooleanParameter
user = User.find_by(id: user_id)
return unless user
Users::Delete.call(user)
# notify admins internally that they need to delete gdpr data
GDPRDeleteRequest.create(user_id: user.id, email: user.email, username: user.username)
return if admin_delete || user.email.blank?
# at this point the user object is already destroyed on the DB,
# thus we pass the data we need to render to deliver the email, not the
# whole object
NotifyMailer.with(name: user.name, email: user.email).account_deleted_email.deliver_now
rescue StandardError => e
ForemStatsClient.count("users.delete", 1, tags: ["action:failed", "user_id:#{user.id}"])
Honeybadger.context({ user_id: user.id })
Honeybadger.notify(e)
end
end
end