Class: WorklingDaemon
- Inherits:
-
Object
- Object
- WorklingDaemon
- Defined in:
- lib/workling_daemon.rb
Class Method Summary collapse
- .boot_with(options) ⇒ Object
- .extract_options(options) ⇒ Object
- .initialize_workling(options) ⇒ Object
- .parse_daemon_options(argv) ⇒ Object
- .parse_workling_options(args) ⇒ Object
- .partition_daemons_options(args) ⇒ Object
- .partition_options(args) ⇒ Object
- .run(options) ⇒ Object
Class Method Details
.boot_with(options) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/workling_daemon.rb', line 77 def self.boot_with() if [:no_rails] # if rails is not booted we need to pull in the workling requires manually require File.join(File.dirname(__FILE__), "workling") else ENV["RAILS_ENV"] = [:rails_env] puts "=> Loading Rails with #{ENV["RAILS_ENV"]} environment..." require [:rails_root] + '/config/environment' ActiveRecord::Base.logger = Workling::Base.logger ActionController::Base.logger = Workling::Base.logger puts '** Rails loaded.' end end |
.extract_options(options) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/workling_daemon.rb', line 55 def self.() result = {} result[:client] = [:client] if [:client] result[:routing] = [:routing] if [:routing] result[:invoker] = [:invoker] if [:invoker] result end |
.initialize_workling(options) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/workling_daemon.rb', line 63 def self.initialize_workling() Workling.load_path = [:load_path] if [:load_path] Workling::Discovery.discover! if [:config_path] Workling.config_path = [:config_path] Workling.config else Workling.config = end Workling.select_and_build_invoker end |
.parse_daemon_options(argv) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/workling_daemon.rb', line 22 def self.(argv) = {} pass_through, args = argv opts = OptionParser.new do |opts| opts. = 'Usage: myapp [options]' opts.separator '' opts.on('-a', '--app-name APP_NAME', String,"specify the process name") { |v| [:app_name] = v } opts.on('-d', '--dir DIR', String, "the directory to run in") { |v| [:dir] = v } opts.on('-m', '--monitor',"specify the process name") { |v| [:monitor] = true } opts.on('-t', '--ontop') { |k, v| pass_through << v } end opts.parse!((args).first) .merge(:ARGV => pass_through) end |
.parse_workling_options(args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/workling_daemon.rb', line 37 def self.(args) = {} opts = OptionParser.new do |opts| opts. = 'Usage: myapp [options]' opts.separator '' opts.on('-n', '--no_rails', "do not load Rails") { |v| [:no_rails] = true } opts.on('-c', '--client CLIENT', String, "specify the client class") { |v| [:client] = v } opts.on('-i', '--invoker INVOKER', String, "specify the invoker class") { |v| [:invoker] = v } opts.on('-r', '--routing ROUTING', String, "specify the routing class") { |v| [:routing] = v } opts.on('-l', '--load-path LOADPATH', String, "specify the load_path for the workers") { |v| [:load_path] = v } opts.on('-f', '--config-path CONFIGPATH', String, "specify the path to the workling.yml file") { |v| [:config_path] = v } opts.on('-e', '--environment ENVIRONMENT', String, "specify the environment") { |v| [:rails_env] = v } opts.on('-p', '--prefix PREFIX', String, "specify the prefix for queues") { |v| [:prefix] = v } end opts.parse!((args).last) end |
.partition_daemons_options(args) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/workling_daemon.rb', line 14 def self.(args) = %W{start stop restart run zap -t --ontop -f --force -h --help --version} pass_through = args.select { |a| .include? a } = args.reject { |a| .include? a } [pass_through, ] end |
.partition_options(args) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/workling_daemon.rb', line 5 def self.(args) daemon = [] workling = [] split_point = args.index("--") || args.size daemon = args[0...split_point] if split_point > 0 workling = args[(split_point+1)..-1] if split_point and split_point < args.size [daemon, workling] end |
.run(options) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/workling_daemon.rb', line 94 def self.run() boot_with poller = initialize_workling() puts "** Starting #{ poller.class }..." puts '** Use CTRL-C to stop.' trap(:INT) { poller.stop; exit } begin poller.listen ensure puts '** No Worklings found.' if Workling::Discovery.discovered.empty? puts '** Exiting' end end |