snipr 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bin/reap_resque_workers +8 -0
- data/lib/snipr/process_signaller.rb +42 -5
- data/lib/snipr/version.rb +1 -1
- data/spec/process_signaller_spec.rb +11 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
|
4
|
-
|
3
|
+
data.tar.gz: 3f2677c94a34966b9d5348c73d2d40b26051390251eefac5a3f8e1ec39c1a3b697b23fcfacdaa17da42a7b5b4073302686cf79b9ce2fc01e55a718cbc7f2063d
|
4
|
+
metadata.gz: 832f8d4ad90744c629518ca67a98762c57a70c4c6373d805c2346c097ca47bf0238fb2e0aa856d29ee84151fd544cd321dfbe7052d519507f4edcb1a14916662
|
5
5
|
SHA1:
|
6
|
-
|
7
|
-
|
6
|
+
data.tar.gz: 4d56124489b903a171f4c73ea3f11016faf5b17c
|
7
|
+
metadata.gz: c9cda0f35966f40058ad8dc4d53efd4cdd8d702a
|
data/bin/reap_resque_workers
CHANGED
@@ -39,6 +39,11 @@ parser = OptionParser.new do |config|
|
|
39
39
|
config.on("-s", "--signal [SIGNAL]", desc) do |signal|
|
40
40
|
options.signal = signal
|
41
41
|
end
|
42
|
+
|
43
|
+
desc = "Perform a dry run which will identify workers to be reaped but not send any signals"
|
44
|
+
config.on("-d", "--dry-run", desc) do
|
45
|
+
options.no_signals = true
|
46
|
+
end
|
42
47
|
end.parse!
|
43
48
|
|
44
49
|
# TODO remove me
|
@@ -52,12 +57,15 @@ unless options.bytes || options.keys || options.alive
|
|
52
57
|
Kernel.exit(-1)
|
53
58
|
end
|
54
59
|
|
60
|
+
output.info("*** DRY RUN ***") if options.no_signals
|
61
|
+
|
55
62
|
signaller = Snipr::ProcessSignaller.new do |signaller|
|
56
63
|
signaller.signal options.signal
|
57
64
|
signaller.target_parent true
|
58
65
|
signaller.include /resque/
|
59
66
|
signaller.include /processing/i
|
60
67
|
signaller.exclude /scheduler/i
|
68
|
+
signaller.dry_run if options.no_signals
|
61
69
|
|
62
70
|
if options.bytes
|
63
71
|
signaller.memory_greater_than(options.bytes)
|
@@ -12,6 +12,7 @@ module Snipr
|
|
12
12
|
# signaller.exclude /scheduler/
|
13
13
|
# signaller.signal "USR1"
|
14
14
|
# signaller.target_parent false
|
15
|
+
# singaller.dry_run
|
15
16
|
#
|
16
17
|
# signaller.on_no_processes do
|
17
18
|
# puts "No processes"
|
@@ -50,7 +51,8 @@ module Snipr
|
|
50
51
|
end
|
51
52
|
|
52
53
|
##
|
53
|
-
# Send the specified signal to all located processes
|
54
|
+
# Send the specified signal to all located processes, invoking
|
55
|
+
# callbacks as appropriate.
|
54
56
|
def send_signals
|
55
57
|
processes = @locator.locate
|
56
58
|
|
@@ -65,6 +67,11 @@ module Snipr
|
|
65
67
|
@on_error.call(e)
|
66
68
|
end
|
67
69
|
|
70
|
+
##
|
71
|
+
# Specify the signal to send to the targetted processes. This should
|
72
|
+
# be a string that maps one of the values listed here:
|
73
|
+
#
|
74
|
+
# http://ruby-doc.org/core-1.8.7/Signal.html#method-c-list
|
68
75
|
def signal(signal)
|
69
76
|
@signal = Signal.list[signal.to_s.upcase].tap do |sig|
|
70
77
|
unless sig
|
@@ -73,37 +80,67 @@ module Snipr
|
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
83
|
+
##
|
84
|
+
# Specify or access the locator collaborator that is responsible for
|
85
|
+
# collecting the processes to operate on
|
76
86
|
def locator(locator=nil)
|
77
87
|
@locator ||= (locator || ProcessLocator.new)
|
78
88
|
end
|
79
89
|
|
90
|
+
##
|
91
|
+
# Callback invoked when no processes are found
|
80
92
|
def on_no_processes(&callback)
|
81
93
|
@on_no_processes = callback
|
82
94
|
end
|
83
95
|
|
96
|
+
##
|
97
|
+
# Callback invoked immediately before sending a signal to a process.
|
98
|
+
# Will send both the signal and the KernelProcess object as returned
|
99
|
+
# by the locator.
|
84
100
|
def before_signal(&callback)
|
85
101
|
@before_signal = callback
|
86
102
|
end
|
87
103
|
|
104
|
+
##
|
105
|
+
# Callback invoked immediately after sending a signal to a process.
|
106
|
+
# Will send both the signal and the KernelProcess object as returned
|
107
|
+
# by the locator.
|
88
108
|
def after_signal(&callback)
|
89
109
|
@after_signal = callback
|
90
110
|
end
|
91
111
|
|
112
|
+
##
|
113
|
+
# Callback invoked if an error is encountered. If this is within
|
114
|
+
# the context of attempting to send a signal to a process, then
|
115
|
+
# the exception, signal and KernelProcess object are sent. Otherwise,
|
116
|
+
# only the exception is sent.
|
92
117
|
def on_error(&callback)
|
93
118
|
@on_error = callback
|
94
119
|
end
|
95
120
|
|
121
|
+
##
|
122
|
+
# Set to true if the signal should be sent to the parent of any
|
123
|
+
# located processes. Defaults to false.
|
96
124
|
def target_parent(flag=false)
|
97
125
|
@target_parent = flag
|
98
126
|
end
|
99
127
|
|
128
|
+
##
|
129
|
+
# Invoke if you want to have callbacks invoked, but not actually
|
130
|
+
# send signals to located processes.
|
131
|
+
def dry_run
|
132
|
+
@dry_run = true
|
133
|
+
end
|
134
|
+
|
100
135
|
private
|
101
136
|
def signal_process(process)
|
102
137
|
@before_signal.call(@signal, process)
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
138
|
+
unless @dry_run
|
139
|
+
if @target_parent
|
140
|
+
Process.kill(@signal, process.ppid)
|
141
|
+
else
|
142
|
+
Process.kill(@signal, process.pid)
|
143
|
+
end
|
107
144
|
end
|
108
145
|
@after_signal.call(@signal, process)
|
109
146
|
rescue StandardError => e
|
data/lib/snipr/version.rb
CHANGED
@@ -76,7 +76,7 @@ module Snipr
|
|
76
76
|
expect(checkins.after_signal).to eq("#{signal} > 6337")
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
context "targetting the parent process" do
|
81
81
|
it "should send the appropriate signal to the parent process and call callbacks" do
|
82
82
|
subject.target_parent true
|
@@ -94,6 +94,16 @@ module Snipr
|
|
94
94
|
expect(checkins.on_error).to eq("Ouch! #{signal} > 6337")
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
context "when doing a dry run" do
|
99
|
+
it "should not send any signals to the process or its parent" do
|
100
|
+
expect(Process).to_not receive(:kill)
|
101
|
+
subject.dry_run
|
102
|
+
subject.send_signals
|
103
|
+
expect(checkins.before_signal).to eq("#{signal} > 6337")
|
104
|
+
expect(checkins.after_signal).to eq("#{signal} > 6337")
|
105
|
+
end
|
106
|
+
end
|
97
107
|
end
|
98
108
|
end
|
99
109
|
end
|