Created
July 10, 2013 21:33
-
-
Save jondeandres/5970532 to your computer and use it in GitHub Desktop.
Push Job to Resque without Resque.
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
require 'yaml' | |
require 'multi_json' | |
module MyApp | |
module Queue | |
extend self | |
def redis | |
MyApp.redis | |
end | |
def encode(object) | |
if MultiJson.respond_to?(:dump) && MultiJson.respond_to?(:load) | |
MultiJson.dump object | |
else | |
MultiJson.encode object | |
end | |
end | |
def add(queue, klass_name, *args) | |
push(queue, class: klass_name, args: args) | |
end | |
def push(queue, item) | |
watch_queue(queue) | |
redis.rpush("resque:queue:#{queue}", encode(item)) | |
end | |
def watch_queue(queue) | |
redis.sadd("resque:queues", queue.to_s) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment