Class: DestroyUserWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/destroy_user_worker.rb

Overview

Background job to destroy a user. This may trigger other destructions in the database (e.g. feeds to which only this user was subscribed).

This is a Sidekiq worker

Instance Method Summary collapse

Instance Method Details

#perform(user_id) ⇒ Object

Destroy a user. This may trigger other destructions (see User class).

Receives as argument:

  • id of the user

This method is intended to be invoked from Sidekiq, which means it is performed in the background.


20
21
22
23
24
25
26
27
28
29
30
# File 'app/workers/destroy_user_worker.rb', line 20

def perform(user_id)
  # Check if the user actually exists
  if !User.exists? user_id
    Rails.logger.error "Trying to destroy non-existing user @#{user_id}, aborting job"
    return
  end
  user = User.find user_id

  Rails.logger.info "Destroying user #{user.id} - #{user.email}"
  user.destroy!
end