Class: Utils::ProbeServer
Defined Under Namespace
Classes: Job
Instance Method Summary collapse
- #commands ⇒ Object
- #continue ⇒ Object
- #env ⇒ Object
- #history_clear ⇒ Object
- #history_list ⇒ Object
-
#initialize(uri) ⇒ ProbeServer
constructor
A new instance of ProbeServer.
- #inspect ⇒ Object (also: #to_s)
- #job ⇒ Object
- #job_enqueue(job_args) ⇒ Object (also: #enqueue)
- #job_kill(signal = :TERM) ⇒ Object
- #job_repeat(job_id = @history.last) ⇒ Object
- #jobs_clear ⇒ Object
- #jobs_list ⇒ Object
- #next_job_id ⇒ Object
- #pause ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(uri) ⇒ ProbeServer
Returns a new instance of ProbeServer.
57 58 59 60 61 62 63 |
# File 'lib/utils/probe_server.rb', line 57 def initialize(uri) @uri = uri @history = [].freeze @jobs_queue = Queue.new @current_job_id = 0 Thread.new { work_loop } end |
Instance Method Details
#commands ⇒ Object
91 92 93 94 95 |
# File 'lib/utils/probe_server.rb', line 91 def commands annotations = self.class.doc_annotations.sort_by(&:first) max_size = annotations.map { |a| a.first.size }.max annotations.map { |n, v| "#{n.to_s.ljust(max_size + 1)}#{v}" } end |
#continue ⇒ Object
106 107 108 109 110 111 |
# File 'lib/utils/probe_server.rb', line 106 def continue mutex.unlock true rescue ThreadError false end |
#env ⇒ Object
184 185 186 |
# File 'lib/utils/probe_server.rb', line 184 def env ENV end |
#history_clear ⇒ Object
178 179 180 181 |
# File 'lib/utils/probe_server.rb', line 178 def history_clear @history = [] true end |
#history_list ⇒ Object
173 174 175 |
# File 'lib/utils/probe_server.rb', line 173 def history_list @history end |
#inspect ⇒ Object Also known as: to_s
84 85 86 |
# File 'lib/utils/probe_server.rb', line 84 def inspect "#<Probe #queue=#{@jobs_queue.size}>" end |
#job ⇒ Object
114 115 116 117 118 |
# File 'lib/utils/probe_server.rb', line 114 def job queue_synchronize do @job end end |
#job_enqueue(job_args) ⇒ Object Also known as: enqueue
125 126 127 128 129 |
# File 'lib/utils/probe_server.rb', line 125 def job_enqueue(job_args) job = Job.new(self, job_args) " → #{job.inspect} enqueued.", type: :info @jobs_queue.push job end |
#job_kill(signal = :TERM) ⇒ Object
133 134 135 |
# File 'lib/utils/probe_server.rb', line 133 def job_kill(signal = :TERM) @pid and Process.kill signal, @pid end |
#job_repeat(job_id = @history.last) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/utils/probe_server.rb', line 162 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 |
#jobs_clear ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/utils/probe_server.rb', line 149 def jobs_clear queue_synchronize do unless @jobs_queue.empty? @jobs_queue.clear "Cleared all queued jobs.", type: :warn true else false end end end |
#jobs_list ⇒ Object
144 145 146 |
# File 'lib/utils/probe_server.rb', line 144 def jobs_list @jobs_queue.instance_variable_get(:@que) end |
#next_job_id ⇒ Object
120 121 122 |
# File 'lib/utils/probe_server.rb', line 120 def next_job_id @current_job_id += 1 end |
#pause ⇒ Object
98 99 100 101 102 103 |
# File 'lib/utils/probe_server.rb', line 98 def pause mutex.lock true rescue ThreadError false end |
#shutdown ⇒ Object
138 139 140 141 |
# File 'lib/utils/probe_server.rb', line 138 def shutdown "Server was shutdown down – HARD!", type: :warn exit! 23 end |
#start ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/utils/probe_server.rb', line 65 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 "commands" to get help for the commands.}, type: :info 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 |