Skip to content

Instantly share code, notes, and snippets.

@brandonhilkert
Created July 1, 2013 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brandonhilkert/5897893 to your computer and use it in GitHub Desktop.
Save brandonhilkert/5897893 to your computer and use it in GitHub Desktop.
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