Class: WatchmonkeyCli::Application
- Inherits:
-
Object
- Object
- WatchmonkeyCli::Application
- Includes:
- Colorize, Configuration::AppHelper, Core, Dispatch, OutputHelper, Checker::AppHelper, Helper
- Defined in:
- lib/watchmonkey_cli/application.rb,
lib/watchmonkey_cli/application/core.rb,
lib/watchmonkey_cli/application/colorize.rb,
lib/watchmonkey_cli/application/dispatch.rb,
lib/watchmonkey_cli/application/configuration.rb,
lib/watchmonkey_cli/application/output_helper.rb
Defined Under Namespace
Modules: Colorize, Core, Dispatch, OutputHelper Classes: Configuration
Constant Summary
Constants included from Colorize
Constants included from Helper
Instance Attribute Summary collapse
-
#checkers ⇒ Object
readonly
Returns the value of attribute checkers.
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Class Method Summary collapse
-
.dispatch(*a) ⇒ Object
= Setup = =========.
Instance Method Summary collapse
- #dump_and_exit! ⇒ Object
- #init_params ⇒ Object
-
#initialize(env, argv) {|_self| ... } ⇒ Application
constructor
A new instance of Application.
- #parse_params ⇒ Object
- #running? ⇒ Boolean
- #sync(&block) ⇒ Object
Methods included from Checker::AppHelper
#init_checkers!, #start_checkers!, #stop_checkers!
Methods included from Configuration::AppHelper
#checker_directory, #checker_files, #config_directory, #config_filename, #config_files, #generate_config, #load_appconfig, #load_checkers!, #load_configs!, #wm_cfg_configfile, #wm_cfg_path
Methods included from Dispatch
#dispatch, #dispatch_generate_config, #dispatch_help, #dispatch_index, #dispatch_info
Methods included from Core
#_queueoff, #close_connections!, #enqueue, #enqueue_sub, #fetch_connection, #fire, #haltpoint, #hook, #logger, #logger_filename, #release_signals, #spawn_threads_and_run!, #trap_signals
Methods included from Colorize
Methods included from OutputHelper
#abort, #debug, #error, #print, #puts, #warn
Methods included from Helper
#human_filesize, #human_number, #human_seconds
Constructor Details
#initialize(env, argv) {|_self| ... } ⇒ Application
Returns a new instance of Application.
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 |
# File 'lib/watchmonkey_cli/application.rb', line 31 def initialize env, argv @boot = Time.current @env, @argv = env, argv @connections = {} @hooks = {} @monitor = Monitor.new @threads = [] @queue = Queue.new @processed = 0 @running = false @opts = { dump: false, # (internal) if true app will dump itself and exit before running any checks dispatch: :index, # (internal) action to dispatch check_for_updates: true, # -z flag colorize: true, # -m flag debug: false, # -d flag threads: 10, # -t flag maxrt: 120.seconds, # max runtime of a single task after which it will be terminated (may break SSH connection), 0/false to not limit runtime conclosewait: 10, # max seconds to wait for connections to be closed (may never if they got killed by maxrt) loop_forever: false, # (internal) loop forever (app mode) loop_wait_empty: 1, # (internal) time to wait in thread if queue is empty silent: false, # -s flag quiet: false, # -q flag stdout: STDOUT, # (internal) STDOUT redirect } init_params yield(self) end |
Instance Attribute Details
#checkers ⇒ Object (readonly)
Returns the value of attribute checkers.
3 4 5 |
# File 'lib/watchmonkey_cli/application.rb', line 3 def checkers @checkers end |
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
3 4 5 |
# File 'lib/watchmonkey_cli/application.rb', line 3 def connections @connections end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
3 4 5 |
# File 'lib/watchmonkey_cli/application.rb', line 3 def hooks @hooks end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/watchmonkey_cli/application.rb', line 3 def opts @opts end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
3 4 5 |
# File 'lib/watchmonkey_cli/application.rb', line 3 def processed @processed end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
3 4 5 |
# File 'lib/watchmonkey_cli/application.rb', line 3 def queue @queue end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
3 4 5 |
# File 'lib/watchmonkey_cli/application.rb', line 3 def threads @threads end |
Class Method Details
.dispatch(*a) ⇒ Object
Setup =
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/watchmonkey_cli/application.rb', line 15 def self.dispatch *a new(*a) do |app| app.load_appconfig app.parse_params begin app.dispatch app.haltpoint rescue Interrupt app.abort("Interrupted", 1) ensure app.fire(:wm_shutdown) app.debug "#{Thread.list.length} threads remain..." end end end |
Instance Method Details
#dump_and_exit! ⇒ Object
97 98 99 100 101 102 |
# File 'lib/watchmonkey_cli/application.rb', line 97 def dump_and_exit! puts " Queue: #{@queue.length}" puts " AppOpts: #{@opts}" puts "Checkers: #{@checkers.keys.join(",")}" exit 9 end |
#init_params ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/watchmonkey_cli/application.rb', line 60 def init_params @optparse = OptionParser.new do |opts| opts. = "Usage: watchmonkey [options]" opts.separator(c "# Application options", :blue) opts.on("--generate-config [myconfig]", "Generates a example config in ~/.watchmonkey") {|s| @opts[:dispatch] = :generate_config; @opts[:config_name] = s } opts.on("-l", "--log [file]", "Log to file, defaults to ~/.watchmonkey/logs/watchmonkey.log") {|s| @opts[:logfile] = s || logger_filename } opts.on("-t", "--threads [NUM]", Integer, "Amount of threads to be used for checking (default: 10)") {|s| @opts[:threads] = s } opts.on("-s", "--silent", "Only print errors and infos") { @opts[:silent] = true } opts.on("-q", "--quiet", "Only print errors") { @opts[:quiet] = true } opts.separator("\n" << c("# General options", :blue)) opts.on("-d", "--debug [lvl=1]", Integer, "Enable debug output") {|l| @opts[:debug] = l || 1 } opts.on("-m", "--monochrome", "Don't colorize output") { @opts[:colorize] = false } opts.on("-h", "--help", "Shows this help") { @opts[:dispatch] = :help } opts.on("-v", "--version", "Shows version and other info") { @opts[:dispatch] = :info } opts.on("-z", "Do not check for updates on GitHub (with -v/--version)") { @opts[:check_for_updates] = false } opts.on("--dump-core", "for developers") { @opts[:dump] = true } end end |
#parse_params ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/watchmonkey_cli/application.rb', line 81 def parse_params @optparse.parse!(@argv) rescue OptionParser::ParseError => e abort(e.) dispatch(:help) exit 1 end |
#running? ⇒ Boolean
89 90 91 |
# File 'lib/watchmonkey_cli/application.rb', line 89 def running? @running end |
#sync(&block) ⇒ Object
93 94 95 |
# File 'lib/watchmonkey_cli/application.rb', line 93 def sync &block @monitor.synchronize(&block) end |