Class: Utils::ProbeServer
Defined Under Namespace
Classes: Job, LogWrapper
Instance Method Summary collapse
- #clear ⇒ Object
- #help ⇒ Object
- #history_clear ⇒ Object
- #history_list ⇒ Object
-
#initialize(uri) ⇒ ProbeServer
constructor
A new instance of ProbeServer.
- #inspect ⇒ Object (also: #to_s)
- #job_enqueue(job_args) ⇒ Object (also: #enqueue)
- #job_repeat(job_id = @history.last) ⇒ Object
- #next_job_id ⇒ Object
- #output_message(msg, type: nil) ⇒ Object
- #print(*msg) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(uri) ⇒ ProbeServer
Returns a new instance of ProbeServer.
44 45 46 47 48 49 50 |
# File 'lib/utils/probe_server.rb', line 44 def initialize(uri) @uri = uri @history = [].freeze @jobs_queue = Queue.new @current_job_id = 0 Thread.new { work_loop } end |
Instance Method Details
#clear ⇒ Object
165 166 167 |
# File 'lib/utils/probe_server.rb', line 165 def clear system "clear" end |
#help ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/utils/probe_server.rb', line 89 def help docs = doc_annotations.sort_by(&:first) docs_size = docs.map { |a| a.first.size }.max format = "%-#{docs_size}s %-3s %s" [ (format % %w[ command sho description ]).on_color(20).white ] << docs.map { |cmd, doc| shortcut = shortcut_of(cmd) and shortcut = "(#{shortcut})" format % [ cmd, shortcut, doc ] } end |
#history_clear ⇒ Object
137 138 139 140 |
# File 'lib/utils/probe_server.rb', line 137 def history_clear @history = [] true end |
#history_list ⇒ Object
132 133 134 |
# File 'lib/utils/probe_server.rb', line 132 def history_list @history end |
#inspect ⇒ Object Also known as: to_s
78 79 80 |
# File 'lib/utils/probe_server.rb', line 78 def inspect "#<Probe #queue=#{@jobs_queue.size}>" end |
#job_enqueue(job_args) ⇒ Object Also known as: enqueue
103 104 105 106 107 |
# File 'lib/utils/probe_server.rb', line 103 def job_enqueue(job_args) job = Job.new(self, job_args) " → #{job.inspect} enqueued.", type: :info @jobs_queue.push job end |
#job_repeat(job_id = @history.last) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/utils/probe_server.rb', line 120 def job_repeat(job_id = @history.last) Job === job_id and job_id = job_id.id if old_job = @history.find { |job| job.id == job_id } job_enqueue old_job.args true else false end end |
#next_job_id ⇒ Object
173 174 175 |
# File 'lib/utils/probe_server.rb', line 173 def next_job_id @current_job_id += 1 end |
#output_message(msg, type: nil) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/utils/probe_server.rb', line 177 def (msg, type: nil) msg.respond_to?(:to_a) and msg = msg.to_a * "\n" msg = case type when :success msg.on_color(22).white when :info msg.on_color(20).white when :warn msg.on_color(94).white when :failure msg.on_color(124).blink.white else msg end STDOUT.puts msg STDOUT.flush self end |
#print(*msg) ⇒ Object
52 53 54 55 56 |
# File 'lib/utils/probe_server.rb', line 52 def print(*msg) if msg.first !~ /^irb: warn: can't alias / # shut your god d*mn wh*re mouth super end end |
#shutdown ⇒ Object
113 114 115 116 |
# File 'lib/utils/probe_server.rb', line 113 def shutdown "Server was shutdown down – HARD!", type: :warn exit 23 end |
#start ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/utils/probe_server.rb', line 58 def start "Starting probe server listening to #{@uri.inspect}.", type: :info DRb.start_service(@uri, self) begin DRb.thread.join rescue Interrupt ARGV.clear << '-f' %{\nEntering interactive mode.}, type: :info help begin old, $VERBOSE = $VERBOSE, nil examine(self) ensure $VERBOSE = old end "Quitting interactive mode, but still listening to #{@uri.inspect}.", type: :info retry end end |