* This change abstracts the DatadogStatsClient into a ForemStatsClient. The purpose of this abstraction is to set the foundation for a subsequent PR that will allow one to use New Relic for recording Forem stats, instead of Datadog, if there is a New Relic configuration found. This specific change creates an abstraction layer that can be built upon, without changing any actual default behavior. All specs still pass. * Use delegate instead of explicit methods. * Delegate instead of explicit methods. * Fix the error. * Refactor according to the suggestions in the comments. * Ooops. Stats work better when all of the code is committed. * Removing the alias of count to increment since that was done in error.
27 lines
1,011 B
Ruby
27 lines
1,011 B
Ruby
module Users
|
|
class DeleteWorker
|
|
include Sidekiq::Worker
|
|
|
|
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
|
|
Users::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
|