Skip to content

Instantly share code, notes, and snippets.

@iboard
Created February 24, 2011 08:07
Show Gist options
  • Save iboard/841907 to your computer and use it in GitHub Desktop.
Save iboard/841907 to your computer and use it in GitHub Desktop.
Usage of CBA, DelayedJob
# Referenced in: http://cba.iboard.cc/p/readme
class User
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paperclip
.....
# Notifications
after_create :async_notify_on_creation
before_destroy :async_notify_on_cancellation
before_update :notify_if_confirmed
.....
private
# Inform admin about sign ups and cancellations of accounts
def async_notify_on_creation
DelayedJob.enqueue('NewSignUpNotifier', Time.now, self.id)
end
# Inform admin about cancellations of accounts
def async_notify_on_cancellation
DelayedJob.enqueue('CancelAccountNotifier', Time.now, self.inspect)
end
# Inform admin if someone confirms an account
def notify_if_confirmed
if attribute_changed?('confirmed_at')
DelayedJob.enqueue('AccountConfirmedNotifier', Time.now, self.id)
end
end
....
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment