Skip to content

Instantly share code, notes, and snippets.

@jondeandres
Created July 10, 2013 21:33
Show Gist options
  • Save jondeandres/5970532 to your computer and use it in GitHub Desktop.
Save jondeandres/5970532 to your computer and use it in GitHub Desktop.
Push Job to Resque without Resque.
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