Class: Delayed::Pool
- Inherits:
-
Object
- Object
- Delayed::Pool
- Defined in:
- lib/delayed/pool.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(args = ARGV) ⇒ Pool
constructor
A new instance of Pool.
- #parse_cli_options! ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args = ARGV) ⇒ Pool
Returns a new instance of Pool.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/delayed/pool.rb', line 13 def initialize(args = ARGV) @args = args @workers = {} @config = { :workers => [] } @options = { :config_file => Settings.default_worker_config_name, :pid_folder => Settings.("tmp/pids"), :tail_logs => true, # only in FG mode } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/delayed/pool.rb', line 11 def @options end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
11 12 13 |
# File 'lib/delayed/pool.rb', line 11 def workers @workers end |
Instance Method Details
#parse_cli_options! ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/delayed/pool.rb', line 65 def op = OptionParser.new do |opts| opts. = "Usage #{$0} <command> <options>" opts.separator %{\nWhere <command> is one of: start start the jobs daemon stop stop the jobs daemon run start and run in the foreground restart stop and then start the jobs daemon status show daemon status } opts.separator "\n<options>" opts.on("-c", "--config [CONFIG_PATH]", "Use alternate config file (default #{[:config_file]})") { |c| [:config_file] = c } opts.on("-p", "--pid", "Use alternate folder for PID files (default #{[:pid_folder]})") { |p| [:pid_folder] = p } opts.on("--no-tail", "Don't tail the logs (only affects non-daemon mode)") { [:tail_logs] = false } opts.on("--with-prejudice", "When stopping, interrupt jobs in progress, instead of letting them drain") { [:kill] ||= true } opts.on("--with-extreme-prejudice", "When stopping, immediately kill jobs in progress, instead of letting them drain") { [:kill] = 9 } opts.on_tail("-h", "--help", "Show this message") { puts opts; exit } end op.parse!(@args) end |
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/delayed/pool.rb', line 24 def run read_config([:config_file]) command = @args.shift case command when 'start' exit 1 if status(print: :alive) == :running daemonize start when 'stop' stop(kill: [:kill]) when 'run' start when 'status' if status exit 0 else exit 1 end when 'restart' pid = self.pid alive = status(pid: pid, print: false) if alive == :running || ([:kill] && alive == :draining) stop(pid: pid, kill: [:kill]) if [:kill] sleep(0.5) while status(pid: pid, print: false) else sleep(0.5) while status(pid: pid, print: false) == :running end end daemonize start when nil puts op else raise("Unknown command: #{command.inspect}") end end |