Created
November 9, 2011 15:54
-
-
Save wireframe/1351867 to your computer and use it in GitHub Desktop.
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
#!/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