utils 0.0.96 → 0.0.97
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/VERSION +1 -1
- data/bin/probe +1 -0
- data/lib/utils/probe_server.rb +97 -11
- data/lib/utils/version.rb +1 -1
- data/utils.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba3f1c86f80cdeb4bd56a41096e45b8b09223e04
|
4
|
+
data.tar.gz: a08b42e891d46dcac8bed897f9d117651cef2c9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 269d1c179beac61cda05b4e569086ac540beaa554a6b44b00566b53e289bb6a929e59d014400e14d7a68e94275fceb49ac4bee862a70f54da1d082bf650826da
|
7
|
+
data.tar.gz: eb07239565819ec09e9de3bb56f711e717e7a139dde3667f824ba52046c57ed72fd9c1b0d781619c300e85ae385640dfb4ed70654715a47c5255822b4cd7787a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.97
|
data/bin/probe
CHANGED
data/lib/utils/probe_server.rb
CHANGED
@@ -7,6 +7,16 @@ end
|
|
7
7
|
module Utils
|
8
8
|
class ProbeServer
|
9
9
|
class Job
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_writer :colorize
|
13
|
+
|
14
|
+
def colorize?
|
15
|
+
!!@colorize
|
16
|
+
end
|
17
|
+
end
|
18
|
+
self.colorize = false
|
19
|
+
|
10
20
|
def initialize(probe_server, args)
|
11
21
|
@id = probe_server.next_job_id
|
12
22
|
@args = args
|
@@ -16,46 +26,91 @@ module Utils
|
|
16
26
|
|
17
27
|
attr_reader :args
|
18
28
|
|
29
|
+
attr_writer :ok
|
30
|
+
|
31
|
+
def ok
|
32
|
+
case @ok
|
33
|
+
when false then 'n'
|
34
|
+
when true then 'y'
|
35
|
+
else '-'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def ok_colorize(string)
|
40
|
+
return string unless self.class.colorize?
|
41
|
+
case @ok
|
42
|
+
when false then string.white.on_red
|
43
|
+
when true then string.black.on_green
|
44
|
+
else string.black.on_yellow
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
19
48
|
def inspect
|
20
|
-
|
49
|
+
ok_colorize(
|
50
|
+
"#<#{self.class}: id=#{id} args=#{args.inspect} ok=#{ok}>"
|
51
|
+
)
|
21
52
|
end
|
53
|
+
|
54
|
+
alias to_s inspect
|
22
55
|
end
|
23
56
|
|
24
57
|
def initialize
|
58
|
+
@history = [].freeze
|
25
59
|
@jobs_queue = Queue.new
|
26
60
|
@current_job_id = 0
|
27
61
|
Thread.new { work_loop }
|
28
62
|
end
|
29
63
|
|
64
|
+
annotate :doc
|
65
|
+
|
66
|
+
def docs
|
67
|
+
annotations = self.class.doc_annotations.sort_by(&:first)
|
68
|
+
max_size = annotations.map { |a| a.first.size }.max
|
69
|
+
annotations.map { |n, v| "#{n.to_s.ljust(max_size + 1)}#{v}" }
|
70
|
+
end
|
71
|
+
|
72
|
+
doc 'Return the currently running job.'
|
73
|
+
def job
|
74
|
+
queue_synchronize do
|
75
|
+
@job
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
30
79
|
def next_job_id
|
31
80
|
@current_job_id += 1
|
32
81
|
end
|
33
82
|
|
34
|
-
|
83
|
+
doc 'Enqueue a new job with the argument array <job_args>.'
|
84
|
+
def job_enqueue(job_args)
|
35
85
|
job = Job.new(self, job_args)
|
36
86
|
output_message "#{job.inspect} enqueued."
|
37
87
|
@jobs_queue.push job
|
38
88
|
end
|
39
|
-
alias
|
89
|
+
alias enqueue job_enqueue
|
40
90
|
|
41
|
-
|
91
|
+
doc 'Stop the process that is working on the current job, if any.'
|
92
|
+
def job_stop
|
42
93
|
@pid and Process.kill :STOP, @pid
|
43
94
|
end
|
44
95
|
|
45
|
-
|
96
|
+
doc 'Continue the process that is working on the current job, if any.'
|
97
|
+
def job_continue
|
46
98
|
@pid and Process.kill :CONT, @pid
|
47
99
|
end
|
48
100
|
|
49
|
-
|
101
|
+
doc 'Shutdown the server.'
|
102
|
+
def server_shutdown
|
50
103
|
output_message "Server was shutdown down – HARD!", :type => :warn
|
51
104
|
exit! 23
|
52
105
|
end
|
53
106
|
|
54
|
-
|
55
|
-
|
107
|
+
doc 'List the currently pending jobs waiting to be run.'
|
108
|
+
def jobs_list
|
109
|
+
@jobs_queue.instance_variable_get(:@que).dup
|
56
110
|
end
|
57
111
|
|
58
|
-
|
112
|
+
doc 'Clear all pending jobs.'
|
113
|
+
def jobs_clear
|
59
114
|
queue_synchronize do
|
60
115
|
unless @jobs_queue.empty?
|
61
116
|
@jobs_queue.clear
|
@@ -67,6 +122,32 @@ module Utils
|
|
67
122
|
end
|
68
123
|
end
|
69
124
|
|
125
|
+
doc 'Repeat the job with <job_id>, it will be assigned a new id, though.'
|
126
|
+
def job_repeat(job_id)
|
127
|
+
if old_job = @history.find { |job| job.id == job_id }
|
128
|
+
job_enqueue old_job.args
|
129
|
+
true
|
130
|
+
else
|
131
|
+
false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
doc 'List the history of run jobs.'
|
136
|
+
def history_list
|
137
|
+
@history.dup
|
138
|
+
end
|
139
|
+
|
140
|
+
doc 'Clear the history of run jobs.'
|
141
|
+
def history_clear
|
142
|
+
@history = []
|
143
|
+
true
|
144
|
+
end
|
145
|
+
|
146
|
+
doc "The environment of the server process, use env['a'] = 'b' and env['a']."
|
147
|
+
def env
|
148
|
+
ENV
|
149
|
+
end
|
150
|
+
|
70
151
|
private
|
71
152
|
|
72
153
|
def queue_synchronize(&block)
|
@@ -96,18 +177,23 @@ module Utils
|
|
96
177
|
Process.wait @pid
|
97
178
|
message = "#{job.inspect} was just run"
|
98
179
|
if $?.success?
|
180
|
+
job.ok = true
|
99
181
|
message << " successfully."
|
100
182
|
output_message message, :type => :success
|
101
183
|
else
|
184
|
+
job.ok = false
|
102
185
|
message << " and failed with exit status #{$?.exitstatus}!"
|
103
186
|
output_message message, :type => :failure
|
104
187
|
end
|
188
|
+
@history += [ @job.freeze ]
|
189
|
+
@history.freeze
|
190
|
+
@job = nil
|
105
191
|
end
|
106
192
|
|
107
193
|
def work_loop
|
108
194
|
loop do
|
109
|
-
job = @jobs_queue.shift
|
110
|
-
run_job job
|
195
|
+
@job = @jobs_queue.shift
|
196
|
+
run_job @job
|
111
197
|
end
|
112
198
|
end
|
113
199
|
|
data/lib/utils/version.rb
CHANGED
data/utils.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: utils 0.0.
|
2
|
+
# stub: utils 0.0.97 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "utils"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.97"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Florian Frank"]
|