Rubykiq
Sidekiq agnostic enqueuing using Redis.
Sidekiq is a fantastic message processing library which has a simple and stable message format. Rubykiq
aims to be a portable library to push jobs in to Sidekiq with as little overhead as possible whilst having feature parity on Sidekiq::Client
's conventions.
Installation
gem 'rubykiq', '~> 1.0'
require 'rubykiq'
Features / Usage Examples
-
Redis has support for alternative drivers, Rubykiq is tested with these in mind. (eg
:synchrony
) - the
:class
parameter can be aClass
or aString
of a Class (eg push jobs to Sidekiq from anywhere, not just where you have Sidekiq classes loaded) - The
:at
parameter supportsTime
,Date
and anyTime.parse
-able strings. - Pushing multiple and singular jobs have the same interface (simply nest args)
- Slightly less gem dependecies, and by that I mean
Sidekiq::Client
withoutCelluloid
(which is already very light!) - Easier configuration (IMO)
# will also detect REDIS_URL, REDIS_PROVIDER and REDISTOGO_URL ENV variables
Rubykiq.url = 'redis://127.0.0.1:6379'
# alternative driver support ( :ruby, :hiredis, :synchrony )
Rubykiq.driver = :synchrony
# defaults to nil
Rubykiq.namespace = 'background'
# uses 'default' queue unless specified
Rubykiq.push(class: 'Worker', args: ['foo', 1, bat: 'bar'])
# args are optionally set to empty
Rubykiq.push(class: 'Scheduler', queue: 'scheduler')
# will batch up multiple jobs
Rubykiq.push(class: 'Worker', args: [['foo'], ['bar']])
# at param can be a 'Time', 'Date' or any 'Time.parse'-able strings
Rubykiq.push(class: 'DelayedHourMailer', at: Time.now + 3600)
Rubykiq.push(class: 'DelayedDayMailer', at: DateTime.now.next_day)
Rubykiq.push(class: 'DelayedMailer', at: '2013-01-01T09:00:00Z')
# alias based sugar
job = { class: 'Worker' }
Rubykiq << job
# create multiple Rubykiq clients with their own drivers
ruby_client = Rubykiq::Client.new
hiredis_client = Rubykiq::Client.new(driver: :hiredis)
# create multiple Rubykiq clients with their own namespaces
foo_client = Rubykiq::Client.new(namespace: 'foo')
bar_client = Rubykiq::Client.new(namespace: 'bar')
Caveats
- It's advised that using Sidekiq::Client's push method when already a dependency is better in most everyday cases
- If you rely on any Sidekiq Middleware, Rubykiq is not aware of them so defaults will not be applied to the job hash.
Build & Dependency Status
Supported Redis Drivers
Supported Ruby Versions
This library aims to support and is tested against the following Ruby implementations:
- Ruby 2.1.0 (drivers: ruby, hiredis, synchrony)
- Ruby 2.0.0 (drivers: ruby, hiredis, synchrony)
- Ruby 1.9.3 (drivers: ruby, hiredis, synchrony)
- JRuby (drivers: ruby)
- Rubinius (drivers: ruby)
Credits
Inspiration:
Cribbed: