Created
September 29, 2014 18:24
-
-
Save darrencauthon/adac5bb79396c27ec18b to your computer and use it in GitHub Desktop.
Using a base class to simplify workers that subscribe to an event
This file contains 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
class OldWorker | |
include Sidekiq::Worker | |
def perform user_event_id | |
user_event = UserEvent.find user_event_id | |
user = User.find user_event.user_id | |
user_application = user.find_application user_event.application_id | |
# do something | |
end | |
end |
This file contains 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
class UserEventSubscriber | |
include Sidekiq::Worker | |
def perform user_event_id | |
@user_event_id = user_event_id | |
execute | |
end | |
def user_event | |
@user_event ||= UserEvent.find @user_event_id | |
end | |
def user | |
@user ||= User.find user_event.user_id | |
end | |
def user_application | |
@user_application ||= user.find_application user_event.application_id | |
end | |
end | |
class NewWorker < UserEventSubscriber | |
def execute | |
#do something, the values are set up for me | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment