Sha256: 129aacb124621d44d58931c04a3dbad178a5ba721d009e91d4ed1a024a82114a
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 KB
Contents
require 'thor' module Rabbithole class CLI < Thor desc 'work', 'Run the rabbithole worker. It listens to jobs and executes them.' option :queues, :alias => :q, :type => :array, :required => true option :num_workers, :alias => :n, :type => :numeric, :default => 1 option :require, :alias => :r, :type => :string, :default => '.' def work load_environment options[:require] @worker = Worker.new(options[:num_workers]) queues = options[:queues] queues << Rabbithole::Connection::DEFAULT_QUEUE if queues.delete('default') || queues.delete('*') queues.each do |queue| @worker.listen_to_queue(queue) end Signal.trap("INT") { shutdown } @worker.join end protected def shutdown puts 'Worker shutting down gracefully...' Thread.new { @worker.stop_listening } end # Entirely copied from resque def load_environment(file) if File.directory?(file) && File.exists?(File.expand_path("#{file}/config/environment.rb")) require "rails" require File.expand_path("#{file}/config/environment.rb") if defined?(::Rails) && ::Rails.respond_to?(:application) # Rails 3 ::Rails.application.eager_load! elsif defined?(::Rails::Initializer) # Rails 2.3 $rails_rake_task = false ::Rails::Initializer.run :load_application_classes end elsif File.file?(file) require File.expand_path(file) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rabbithole-0.0.3 | lib/rabbithole/cli.rb |
rabbithole-0.0.2 | lib/rabbithole/cli.rb |
rabbithole-0.0.1 | lib/rabbithole/cli.rb |