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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 266c90fe7703c6489e6d66096965c92b59f80e1c
4
- data.tar.gz: 51d36018ce055b1887c081ae93f401c826f6d79f
3
+ metadata.gz: ba3f1c86f80cdeb4bd56a41096e45b8b09223e04
4
+ data.tar.gz: a08b42e891d46dcac8bed897f9d117651cef2c9b
5
5
  SHA512:
6
- metadata.gz: 77964738b8e9413f48ad1b73cef2709e789539fa9ee4227953cbcebfbce40cde887319b7ccf06653828093e5994c04516c624cfe383804fc223cfc86ee3a8f43
7
- data.tar.gz: b567bc1621be74d10258a5e3f1a6040b0a1fb719ddfba11d14ae94fe000e14f46bfacff07d01576ec5b59137616a4808e24b285270b5bb2fa027daf8b4c1cf1e
6
+ metadata.gz: 269d1c179beac61cda05b4e569086ac540beaa554a6b44b00566b53e289bb6a929e59d014400e14d7a68e94275fceb49ac4bee862a70f54da1d082bf650826da
7
+ data.tar.gz: eb07239565819ec09e9de3bb56f711e717e7a139dde3667f824ba52046c57ed72fd9c1b0d781619c300e85ae385640dfb4ed70654715a47c5255822b4cd7787a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.96
1
+ 0.0.97
data/bin/probe CHANGED
@@ -71,6 +71,7 @@ def start_server
71
71
  end
72
72
 
73
73
  def connect_server
74
+ Utils::ProbeServer::Job.colorize = true
74
75
  puts "Connecting probe server on #{$uri.inspect}."
75
76
  DRb.start_service
76
77
  probe_server = DRbObject.new_with_uri($uri)
@@ -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
- "#<#{self.class}: id=#{id} args=#{args.inspect}>"
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
- def enqueue(job_args)
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 run enqueue
89
+ alias enqueue job_enqueue
40
90
 
41
- def stop
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
- def continue
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
- def shutdown
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
- def list_jobs
55
- @jobs_queue.instance_variable_get(:@que)
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
- def clear_jobs
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
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.0.96'
3
+ VERSION = '0.0.97'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/utils.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.0.96 ruby lib
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.96"
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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.96
4
+ version: 0.0.97
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank