Sha256: 907d1fb0ff60c8d24f379fdcf9caf836225361454ca120be99330ca24985262c

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

require 'dante'

module Backburner
  class CLI

    def self.start(args)
      runner = Dante::Runner.new('backburner')
      runner.description = "Execute a backburner worker process"
      runner.with_options do |opts|
        opts.on("-r", "--require PATH", String, "The path to load as the environment.") do |req|
          options[:require] = req
        end
        opts.on("-q", "--queues PATH", String, "The specific queues to work.") do |queues|
          options[:queues] = queues
        end
      end
      runner.execute do |opts|
        queues = (opts[:queues] ? opts[:queues].split(',') : nil) rescue nil
        load_enviroment(opts[:require])
        p queues
        Backburner.work(queues)
      end
    end

    protected

      def self.load_enviroment(file = nil)
        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.directory?(file) && File.exists?(File.expand_path("#{file}/config/boot.rb"))
          if defined?(::Padrino)
            # Padrino
            require "padrino"
            require File.expand_path("#{file}/config/boot.rb")
          end
        elsif File.file?(file)
          require File.expand_path(file)
        end
      end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
backburner-0.4.5 lib/backburner/cli.rb
backburner-0.4.4 lib/backburner/cli.rb
backburner-0.4.3 lib/backburner/cli.rb
backburner-0.4.2 lib/backburner/cli.rb
backburner-0.4.1 lib/backburner/cli.rb