Created
April 12, 2013 01:42
-
-
Save nateberkopec/5368626 to your computer and use it in GitHub Desktop.
Comparison of top 3 Ruby background job systems on Ruby Toolbox
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
# DelayedJob | |
@user.delay.activate!(@device) # Delay any object | |
Notifier.delay.signup(@user) # Delay ActionMailer | |
#DelayedJob supports a number of ways to make methods async | |
def send_mailer | |
# Some other code | |
end | |
handle_asynchronously :send_mailer, :priority => 20 | |
def in_the_future | |
# Some other code | |
end | |
# 5.minutes.from_now will be evaluated when in_the_future is called | |
handle_asynchronously :in_the_future, :run_at => Proc.new { 5.minutes.from_now } | |
class NewsletterJob < Struct.new(:text, :emails) | |
def perform | |
emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) } | |
end | |
end | |
# DJ's version of a worker class. No modules required. DJ stores the entire | |
# object in the database as YAML when it is enqueued. | |
Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).collect(&:email)) |
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
# Resque 2 | |
# As far as I can tell, enqueueing class or instance methods a la Sidekiq/DJ: | |
# @user.delay.update_orders(1, 2, 3) | |
# is not supported by Resque 2.0, though you could probably code it up yourself. | |
class ImageConversionJob | |
def work | |
# convert some kind of image here | |
end | |
end | |
resque = Resque.new | |
resque << ImageConversionJob.new | |
# Resque 2 worker classes do not require inclusion of a module |
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
# Sidekiq | |
User.delay.do_some_stuff(current_user.id, 20) # Delay any class method | |
@user.delay.update_orders(1, 2, 3) # Delay any instance method | |
UserMailer.delay.welcome_email(@user.id) # Delay ActionMailer | |
object.delay(:queue => 'tracking').method # Supports named queues | |
# Sidekiq supports but does not encourage delaying methods on instances | |
class HardWorker | |
include Sidekiq::Worker | |
def perform(name, count) | |
puts 'Doing hard work' | |
end | |
end | |
HardWorker.perform_async('bob', 5) | |
# Sidekiq's worker classes require you to include Sidekiq::Worker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment