Skip to content

Instantly share code, notes, and snippets.

@kiafaldorius
Created December 17, 2010 08:12
Show Gist options
  • Save kiafaldorius/744654 to your computer and use it in GitHub Desktop.
Save kiafaldorius/744654 to your computer and use it in GitHub Desktop.
This class lets you enqueue class methods with Delayed Job
# This class lets you enqueue class methods with Delayed Job
# For Rails, name this delayed_profit.rb and put it in your app/models directory
# For the others, do what you do to load files
# Usage: Assuming Notifier is your ActionMailer class then ...
# Delayed::Job.enqueue DelayedProfit.new(Notifier,
# :deliver_profit_notification, 'hey!', 'we profitted')
# This causes Delayed Job to execute
# Notifier.deliver_profit_notification('hey!', 'we profitted')
class DelayedProfit
def initialize(klass, send_method, *params)
@klass = klass.to_s
@send_method = send_method
@params = params
end
def perform
@klass.constantize.send(@send_method, *@params)
end
end
# As a side note, if you are going to use this with ActionMailer models,
# I suggest you NOT pass in models but instead pass in the ids of the models
# and do the Model.find(id) from inside the ActionMailer model's method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment