#!/usr/bin/env ruby # # This command is expected to be run in the root of a Rails application which has a Job model class # and has an initializer to configure JobDispatch. ROOT_DIR = Dir.pwd APP_PATH = File.expand_path('config/application.rb', ROOT_DIR) unless File.exist?('config/job_dispatch.yml') $stderr.puts "Configuration file at 'config/job_dispatch.yml' not found." exit 1 end if ENV['BUNDLE_GEMFILE'] || File.exists('Gemfile') require 'bundler/setup' end require 'job_dispatch' # boot the rails app so we can access the Rails stored job queue. require File.expand_path('config/boot.rb', ROOT_DIR) ENV["RAILS_ENV"] ||= "development" JobDispatch.load_config_from_yml('config/job_dispatch.yml', ENV["RAILS_ENV"]) # TODO: Find a way to start the dispatcher with only ActiveRecord/Mongoid skipping the rest of rails # as it uses ~100MB RAM. require File.expand_path('config/environment.rb', ROOT_DIR) endpoint = JobDispatch.config.broker[:connect] if endpoint.nil? || endpoint.empty? $stderr.puts "No Job Dispatch broker connect address has been specified." exit 1 end worker = JobDispatch::Worker.new(endpoint, JobDispatch.config.worker_options) worker.run