quebert: A pluggable worker queue inspired by Beanstalk

It must be Video Games of the 80s week on The Changelog. First Asteroids then Space Invaders, and now Q*Bert.

Quebert from Brad Gessler aims to improve on async_observer by borrowing ideas from Resque and DelayedJob. Features include support for multiple backends (including Beanstalk), ActiveRecord integration, pluggable exception handling, and daemonization.
To create a job in Quebert, just inherit from Quebert::Job:

class WackyMathWizard < Quebert::Job
  def perform(*nums)
    nums.inject(0){|sum, n| sum = sum + n}
  end
end

Jobs can be dropped in a queue:

Quebert.backend.put WackyMathWizard, 1, 2, 3

… or enqueue themselves:

WackyMathWizard.enqueue 4, 5, 6

Jobs are then run through the familiar perform method:

Quebert.backend.reserve.perform # => 6
Quebert.backend.reserve.perform # => 15

Async call pattern

If the async call pattern is more your bag, Quebert does that, too. Just include the AsyncSender module in your class:

class Greeter
  include Quebert::AsyncSender

  def initialize(name)
    @name = name
  end

  def sleep_and_greet(time_of_day)
    sleep 10000 # Sleeping, get it?
    "Oh! Hi #{name}! Good #{time_of_day}."
  end

  def self.budweiser_greeting(name)
    "waaazup #{name}!"
  end
end

You can then call methods asynchronously with async_send:

walmart_greeter = Greeter.new("Brad")
walmart_greeter.async_send(:sleep_and_greet, "morning")

Nifty. Be sure and check the README for advance usage including backend configuration.

[Source on GitHub]

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

 
0:00 / 0:00