Created
July 1, 2013 01:53
-
-
Save brandonhilkert/5897893 to your computer and use it in GitHub Desktop.
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 EmailJob | |
def perform(user_id) | |
UserMailer.welcome(user_id).deliver | |
end | |
# This include must come after #perform | |
# otherwise the alias_method bullcrap will fail | |
include SuckerPunch::Job | |
end | |
module SuckerPunch | |
module Job | |
def self.included(base) | |
base.send(:include, ::Celluloid) | |
base.class_eval do | |
alias_method :perform_without_pool_check, :perform | |
alias_method :perform, :perform_with_pool_check | |
end | |
end | |
def perform_with_pool_check(*args, &block) | |
define_celluloid_pool | |
perform_without_pool_check(*args, &block) | |
end | |
private | |
def define_celluloid_pool | |
unless SuckerPunch::Queues.registered?(queue_name) | |
Celluloid::Actor[queue_name] = self.class.send(:pool) | |
SuckerPunch::Queues.register(queue_name) | |
end | |
end | |
def queue_name | |
self.class.to_s.underscore.to_sym | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment