Class: Commands::Periodic

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/periodic.rb

Instance Method Summary collapse

Instance Method Details

#optionsObject

holds the options that were passed you can set any initial defaults here



13
14
15
16
# File 'lib/commands/periodic.rb', line 13

def options
  @options ||= {
  }
end

#register(opts, global_options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/commands/periodic.rb', line 26

def register(opts, global_options)
  opts.banner = "Usage: periodic [options]"
  opts.description = "Run a periodic command"

  opts.on('-c', "--command name", "Required - Command to run.") do |v|
    options[:command] = v
  end

  opts.on('-i', "--interval value", Integer, "Required - Interval in seconds.") do |v|
    options[:interval] = v
  end

end

#required_optionsObject

required options



19
20
21
22
23
24
# File 'lib/commands/periodic.rb', line 19

def required_options
  @required_options ||= Set.new [
      :command,
      :interval
  ]
end

#run(global_options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/commands/periodic.rb', line 40

def run(global_options)

  # see if we can open the config file - we append the .config suffix
  # the file is expected to be in JSON format
  command = options[:command]
  interval = options[:interval]

  while true
    EbmSharedLib::CL.do_cmd_result(command)
    sleep(interval)
  end
end