Skip to content

Instantly share code, notes, and snippets.

@jhubert
Created February 26, 2017 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhubert/fd8d48f0663e7140b1119485200f8553 to your computer and use it in GitHub Desktop.
Save jhubert/fd8d48f0663e7140b1119485200f8553 to your computer and use it in GitHub Desktop.
Middle point for my article on refactoring in the real world
# Disable users who have email addresses that are bouncing
class DisableRejectedEmailsJob
include Sidekiq::Worker
def perform
now = Time.zone.now
target_users = User.enabled.where(email: rejected_emails)
# Load the ids before we update the users or the pluck query will return nothing
target_user_ids = target_users.pluck(:id)
target_users.update_all(disabled_at: now)
target_user_ids.each { |user_id| track_disabling_of(user_id) }
end
private
def track_disabling_of(user_id)
Activity.track(
'user:disable',
target_type: User.name,
target_id: user_id
)
end
# Returns an array of email addresses
def rejected_emails
# Logic for pulling recently bounced email address from our mail server
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment