Class: Hotdog::Commands::Down

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

Constant Summary

Constants inherited from BaseCommand

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

Constructor Details

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

Instance Method Details

#run(args = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hotdog/commands/down.rb', line 8

def run(args=[])
  if args.index("--start").nil?
    start = Time.new
  else
    start = Time.parse(args[args.index("--start") + 1])
    args.slice!(args.index("--start"), 2)
  end
  if args.index("--downtime").nil?
    downtime = 86400
  else
    downtime = args[args.index("--downtime") + 1].to_i
    args.slice!(args.index("--downtime"), 2)
  end

  args.each do |arg|
    if arg.index(":").nil?
      scope = "host:#{arg}"
    else
      scope = arg
    end
    code, schedule = @dog.schedule_downtime(scope, :start => start.to_i, :end => (start+downtime).to_i)
    logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, start.to_i, (start+downtime).to_i, code.inspect, schedule.inspect])
    if code.to_i / 100 != 2
      raise("dog.schedule_downtime(%s, ...) returns [%s, %s]" % [scope.inspect, code.inspect, schedule.inspect])
    end
  end

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