Skip to content

Instantly share code, notes, and snippets.

@wireframe
Created November 9, 2011 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wireframe/1351867 to your computer and use it in GitHub Desktop.
Save wireframe/1351867 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'thor'
module Backgrounded
class CLI < Thor
desc 'enqueue', 'enqueue a clazz.method invocation for resque backgrounded workers'
method_option :queue, :aliases => "-q", :desc => "resque queue to enqueue the operation to", :default => 'backgrounded'
method_option :rails_env, :aliases => '-e', :desc => 'control which rails env used to load the redis config', :default => 'production'
# operation Clazz.method to enqueue into resque backgrounded queue (ex: Foo.bar)
def enqueue(operation)
require 'bundler'
Bundler.setup
require "thread"
require "active_support/inflector"
require "resque"
require "yaml"
clazz, method = operation.to_s.split('.')
raise 'invalid operation' unless clazz && method
Resque.redis = YAML.load_file(File.join("config", "resque.yml"))[options[:rails_env]]
Resque::Job.create(options[:queue], 'Backgrounded::Handler::ResqueHandler', clazz, -1, method)
end
end
end
Backgrounded::CLI.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment