watchmonkey_cli 1.9.1 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b298374ee831d146ff709f5ec48c032eb5b3806705e08b899224c0efbe0f6bd
4
- data.tar.gz: 0f58a4b638370a9f248f9afbab36c2f4e30296ac222d8e8d46ab08e6277f78cd
3
+ metadata.gz: 2130727c6200a2fffef5220a52052df322b126e610dfdf18431f4c05841bd286
4
+ data.tar.gz: e8130e7bd3267c92a3352d102a577d7bd047c35905eae7291e9ddfe49da822e9
5
5
  SHA512:
6
- metadata.gz: d7b084fe27627f5e0890567ea45dfa05b9b39e40edddfc411ee1fd4246ef7a3c1b2716d323bca4241748a40ba43f620ee098b1699babc71dc60241a2dee7d9d0
7
- data.tar.gz: fadca599fafa8c1adb5aaef7e9b91a6f89d9b191f8a8c89a9385366c0c4d9924e0061408ae032c5490c32db68ce5a7c06b7ea006659b3a72e486062e7cdc20e6
6
+ metadata.gz: '053523431494e83e9c6e72f4b1d1313cf3be03fe3f5a566deabcc2e2d22ec0db17d7d04f82a0fddbc91cd88024267d36d7a8bd1ffe7b5bc6c1990b6cfd1d41ba'
7
+ data.tar.gz: d4072ceafae6848acef9e34591cf1e33ddbf6df248eafa8f6018f0c1b7feb1c66e2238b388724a15cd5fa82669b9a6cd21b1f56f0518adc4c0ce040c730074b3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.1
1
+ 1.10.0
@@ -12,6 +12,14 @@ module MyWatchmonkeyCheckers
12
12
  # e.g. my_checker "http://google.com", some_option: true
13
13
  self.checker_name = "my_checker"
14
14
 
15
+ # Maximum amount of time this task may run before it gets killed.
16
+ # Set to 0/false to have no time limit whatsoever.
17
+ # Set to proc to evaluate at runtime
18
+ # Defaults to app.opts[:maxrt] if nil/unset
19
+ #self.maxrt = false
20
+ #self.maxrt = 5.minutes
21
+ #self.maxrt = ->(app, checker, args){ app.opts[:maxrt] && app.opts[:maxrt] * 2 }
22
+
15
23
  # Called by configuration defining a check with all the arguments.
16
24
  # e.g. my_checker "http://google.com", some_option: true
17
25
  # Should invoke `app.enqueue` which will by default call `#check!` method with given arguments.
@@ -33,6 +33,7 @@ require "watchmonkey_cli/application/dispatch"
33
33
  require "watchmonkey_cli/application"
34
34
 
35
35
  # require buildin checkers
36
+ require "watchmonkey_cli/checkers/dev_pry"
36
37
  require "watchmonkey_cli/checkers/ftp_availability"
37
38
  require "watchmonkey_cli/checkers/mysql_replication"
38
39
  require "watchmonkey_cli/checkers/ssl_expiration"
@@ -45,6 +45,8 @@ module WatchmonkeyCli
45
45
  colorize: true, # -m flag
46
46
  debug: false, # -d flag
47
47
  threads: 10, # -t flag
48
+ 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
49
+ conclosewait: 10, # max seconds to wait for connections to be closed (may never if they got killed by maxrt)
48
50
  loop_forever: false, # (internal) loop forever (app mode)
49
51
  loop_wait_empty: 1, # (internal) time to wait in thread if queue is empty
50
52
  silent: false, # -s flag
@@ -81,7 +81,10 @@ module WatchmonkeyCli
81
81
 
82
82
  def close_connections!
83
83
  @connections.each do |type, clist|
84
- clist.each{|id, con| con.close! }
84
+ clist.each do |id, con|
85
+ debug "[SHUTDOWN] closing #{type} connection #{id} #{con}"
86
+ con.close!
87
+ end
85
88
  end
86
89
  end
87
90
 
@@ -98,7 +101,19 @@ module WatchmonkeyCli
98
101
  begin
99
102
  result = Checker::Result.new(checker, *a)
100
103
  checker.debug(result.str_running)
101
- checker.safe(result.str_safe) { cb.call(result, *a) }
104
+ checker.safe(result.str_safe) {
105
+ timeout = checker.class.maxrt.nil? ? @opts[:maxrt] : checker.class.maxrt
106
+ timeout = timeout.call(self, checker, a) if timeout.respond_to?(:call)
107
+ begin
108
+ if timeout && timeout > 0
109
+ Timeout::timeout(timeout) { cb.call(result, *a) }
110
+ else
111
+ cb.call(result, *a)
112
+ end
113
+ rescue Timeout::Error => ex
114
+ result.error! "TIMEOUT: did not finish within #{timeout} seconds, task killed!"
115
+ end
116
+ }
102
117
  fire(:result_dump, result, a, checker)
103
118
  result.dump!
104
119
  ensure
@@ -41,7 +41,7 @@ module WatchmonkeyCli
41
41
  ensure
42
42
  @running = false
43
43
  stop_checkers!
44
- close_connections!
44
+ Timeout::timeout(@opts[:conclosewait]) { close_connections! } rescue false
45
45
  release_signals
46
46
  end
47
47
 
@@ -17,6 +17,14 @@ module WatchmonkeyCli
17
17
  @checker_name = name
18
18
  end
19
19
 
20
+ def self.maxrt
21
+ @maxrt
22
+ end
23
+
24
+ def self.maxrt= seconds
25
+ @maxrt = seconds
26
+ end
27
+
20
28
  module AppHelper
21
29
  def init_checkers!
22
30
  @checkers = {}
@@ -168,8 +176,10 @@ module WatchmonkeyCli
168
176
  error "#{descriptor}retry #{tries} reason is `#{e.class}: #{e.message}'"
169
177
  e.backtrace.each{|l| debug "\t\t#{l}" }
170
178
  end
171
- sleep 1
172
- retry
179
+ unless $wm_runtime_exiting
180
+ sleep 1
181
+ retry
182
+ end
173
183
  end
174
184
  error "#{descriptor}retries exceeded"
175
185
  end
@@ -0,0 +1,29 @@
1
+ module WatchmonkeyCli
2
+ module Checkers
3
+ class DevPry < Checker
4
+ self.checker_name = "dev_pry"
5
+ self.maxrt = false
6
+
7
+ def enqueue host, opts = {}
8
+ host = app.fetch_connection(:loopback, :local) if !host || host == :local
9
+ host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
10
+ app.enqueue(self, host, opts)
11
+ end
12
+
13
+ def check! result, host, opts = {}
14
+ if app.opts[:threads] > 1
15
+ result.error! "pry only works properly within the main thread, run watchmonkey with `-t0`"
16
+ return
17
+ end
18
+
19
+ begin
20
+ require "pry"
21
+ binding.pry
22
+ 1+1 # pry may bug out otherwise if it's last statement
23
+ rescue LoadError => ex
24
+ result.error! "pry is required (gem install pry)! #{ex.class}: #{ex.message}"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,4 +1,4 @@
1
1
  module WatchmonkeyCli
2
- VERSION = "1.9.1"
2
+ VERSION = "1.10.0"
3
3
  UPDATE_URL = "https://raw.githubusercontent.com/2called-chaos/watchmonkey_cli/master/VERSION"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchmonkey_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Pachnit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2020-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -123,6 +123,7 @@ files:
123
123
  - lib/watchmonkey_cli/application/dispatch.rb
124
124
  - lib/watchmonkey_cli/application/output_helper.rb
125
125
  - lib/watchmonkey_cli/checker.rb
126
+ - lib/watchmonkey_cli/checkers/dev_pry.rb
126
127
  - lib/watchmonkey_cli/checkers/ftp_availability.rb
127
128
  - lib/watchmonkey_cli/checkers/mysql_replication.rb
128
129
  - lib/watchmonkey_cli/checkers/ssl_expiration.rb