Created
February 26, 2017 21:16
-
-
Save jhubert/fd8d48f0663e7140b1119485200f8553 to your computer and use it in GitHub Desktop.
Middle point for my article on refactoring in the real world
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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