Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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