Last active
August 29, 2015 14:01
-
-
Save kbighorse/f58579ea2223217b4616 to your computer and use it in GitHub Desktop.
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
| class Vehicle | |
| def delayed_do_something | |
| DoSomethingWorker.perform_async(self.id) | |
| end | |
| # this should be where all the real action is | |
| def do_something | |
| puts 'hello' | |
| end | |
| # use delayed_send* and send_* for emails | |
| def delayed_send_notification | |
| SendNotificationWorker.perform_async(self.id) | |
| end | |
| def send_notification | |
| # mailer method doesn't include the send* prefix | |
| VehicleMailer.notification(self).deliver | |
| end | |
| private # only this class can call these workers | |
| # end all worker class names with *Worker | |
| class DoSomethingWorker # could also inherit from a specialty worker we define | |
| include Sidekiq::Worker | |
| # no business logic here, keep the workers stupid | |
| def perform(vehicle_id) | |
| vehicle = Vehicle.find_by_id vehicle_id | |
| vehicle.do_something | |
| end | |
| end | |
| # email workers, all begin with Send* and end with *Worker | |
| class SendNotificationWorker # could also inherit from a specialty worker we define | |
| include Sidekiq::Worker | |
| def perform(vehicle_id) | |
| vehicle = Vehicle.find_by_id vehicle_id | |
| vehicle.send_notification | |
| end | |
| end | |
| end | |
| class VehicleMailer < NovoedMailer # NovoedMailer includes shared behavior across all mailers | |
| # mailer method doesn't include the send* prefix | |
| def notification(vehicle) | |
| # the usual | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment