Created
April 27, 2010 08:08
-
-
Save dekart/380482 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
| # RAILS_ROOT/lib/jobs/queue.rb | |
| module Jobs | |
| module Queue | |
| mattr_accessor :logger | |
| def enqueue(*args) | |
| Resque.enqueue(self, *args) | |
| end | |
| def queued?(*args) | |
| Resque.queued?(self, *args) | |
| end | |
| def error(id, message) | |
| logger.error("#{Time.now} - #{name} [#{id}] - #{message}") | |
| end | |
| def debug(id, message) | |
| logger.debug("#{Time.now} - #{name} [#{id}] - #{message}") | |
| end | |
| end | |
| end |
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
| # RAILS_ROOT/lib/jobs/mailing/user_signup.rb | |
| module Jobs | |
| module Mailing | |
| class UserSignup | |
| extend ::Jobs::Queue | |
| @queue = :mailing | |
| def self.perform(user_id) | |
| unless user = User.find_by_id(user_id) | |
| error(user_id, "Cannot find user!") | |
| return | |
| end | |
| if user.active? | |
| error(user_id, "User already activated!") | |
| return | |
| end | |
| debug(user_id, "Sending signup notification email...") | |
| Mailer::User.deliver_signup_notification(user) | |
| debug(user_id, "Done!") | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment