Class: Hotdog::Commands::Down
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Hotdog::Commands::Down
- Defined in:
- lib/hotdog/commands/down.rb
Instance Attribute Summary
Attributes inherited from BaseCommand
#application, #logger, #options, #persistent_db_path
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 (optparse, ={}) default_option(, :downtime, 86400) default_option(, :retry, 5) default_option(, :start, Time.new) optparse.on("--downtime DURATION") do |v| [:downtime] = v.to_i end optparse.on("--retry NUM") do |v| [:retry] = v.to_i end optparse.on("--retry-delay SECONDS") do |v| [:retry_delay] = v.to_i end optparse.on("--start TIME") do |v| [: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 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hotdog/commands/down.rb', line 26 def run(args=[], ={}) scopes = args.map { |arg| if arg.index(":").nil? "host:#{arg}" else arg end } hosts = scopes.select { |scope| scope.start_with?("host:") }.map { |scope| scope.slice("host:".length, scope.length) } if 0 < hosts.length # Try reloading database after error as a workaround for nested transaction. with_retry(error_handler: ->(error) { reload }) do if open_db @db.transaction do hosts.each_slice(SQLITE_LIMIT_COMPOUND_SELECT) do |hosts| execute_db(@db, "DELETE FROM hosts_tags WHERE host_id IN ( SELECT id FROM hosts WHERE name IN (%s) );" % hosts.map { "?" }.join(", "), hosts) execute_db(@db, "DELETE FROM hosts WHERE name IN (%s);" % hosts.map { "?" }.join(", "), hosts) end end end end end scopes.each do |scope| with_retry() do schedule_downtime(scope, ) end end end |