Class: Hotdog::Commands::Down

Inherits:
BaseCommand show all
Defined in:
lib/hotdog/commands/down.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::MASK_DATABASE, BaseCommand::MASK_QUERY, BaseCommand::PERSISTENT_DB

Instance Attribute Summary

Attributes inherited from BaseCommand

#application, #logger, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#execute, #fixed_string?, #initialize, #parse_options, #reload

Constructor Details

This class inherits a constructor from Hotdog::Commands::BaseCommand

Instance Method Details

#define_options(optparse, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hotdog/commands/down.rb', line 8

def define_options(optparse, options={})
  default_option(options, :downtime, 86400)
  default_option(options, :retry, 5)
  default_option(options, :start, Time.new)
  optparse.on("--downtime DURATION") do |v|
    options[:downtime] = v.to_i
  end
  optparse.on("--retry NUM") do |v|
    options[:retry] = v.to_i
  end
  optparse.on("--retry-delay SECONDS") do |v|
    options[:retry_delay] = v.to_i
  end
  optparse.on("--start TIME") do |v|
    options[:start] = Time.parse(v)
  end
end

#run(args = [], options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hotdog/commands/down.rb', line 26

def run(args=[], options={})
  args.each do |arg|
    if arg.index(":").nil?
      scope = "host:#{arg}"
    else
      scope = arg
    end
    with_retry(options) do
      schedule_downtime(scope, options)
    end
  end

  # Remove persistent.db to schedule update on next invocation
  if @db
    close_db(@db)
  end
  FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
end