Class: Utils::ProbeServer
Defined Under Namespace
Classes: Job
Instance Method Summary collapse
- #docs ⇒ Object
- #env ⇒ Object
- #history_clear ⇒ Object
- #history_list ⇒ Object
-
#initialize ⇒ ProbeServer
constructor
A new instance of ProbeServer.
- #job ⇒ Object
- #job_continue ⇒ Object
- #job_enqueue(job_args) ⇒ Object (also: #enqueue)
- #job_kill(signal) ⇒ Object
- #job_repeat(job_id) ⇒ Object
- #job_stop ⇒ Object
- #jobs_clear ⇒ Object
- #jobs_list ⇒ Object
- #next_job_id ⇒ Object
- #server_shutdown ⇒ Object
Constructor Details
#initialize ⇒ ProbeServer
Returns a new instance of ProbeServer.
57 58 59 60 61 62 |
# File 'lib/utils/probe_server.rb', line 57 def initialize @history = [].freeze @jobs_queue = Queue.new @current_job_id = 0 Thread.new { work_loop } end |
Instance Method Details
#docs ⇒ Object
66 67 68 69 70 |
# File 'lib/utils/probe_server.rb', line 66 def docs 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 |
#env ⇒ Object
153 154 155 |
# File 'lib/utils/probe_server.rb', line 153 def env ENV end |
#history_clear ⇒ Object
147 148 149 150 |
# File 'lib/utils/probe_server.rb', line 147 def history_clear @history = [] true end |
#history_list ⇒ Object
142 143 144 |
# File 'lib/utils/probe_server.rb', line 142 def history_list @history.dup end |
#job ⇒ Object
73 74 75 76 77 |
# File 'lib/utils/probe_server.rb', line 73 def job queue_synchronize do @job end end |
#job_continue ⇒ Object
102 103 104 |
# File 'lib/utils/probe_server.rb', line 102 def job_continue job_kill :CONT end |
#job_enqueue(job_args) ⇒ Object Also known as: enqueue
84 85 86 87 88 |
# File 'lib/utils/probe_server.rb', line 84 def job_enqueue(job_args) job = Job.new(self, job_args) "#{job.inspect} enqueued." @jobs_queue.push job end |
#job_kill(signal) ⇒ Object
92 93 94 |
# File 'lib/utils/probe_server.rb', line 92 def job_kill(signal) @pid and Process.kill signal, @pid end |
#job_repeat(job_id) ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/utils/probe_server.rb', line 131 def job_repeat(job_id) Job === job_id and job_id = job.id if old_job = @history.find { |job| job.id == job_id } job_enqueue old_job.args true else false end end |
#job_stop ⇒ Object
97 98 99 |
# File 'lib/utils/probe_server.rb', line 97 def job_stop job_kill :STOP end |
#jobs_clear ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/utils/probe_server.rb', line 118 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
113 114 115 |
# File 'lib/utils/probe_server.rb', line 113 def jobs_list @jobs_queue.instance_variable_get(:@que).dup end |
#next_job_id ⇒ Object
79 80 81 |
# File 'lib/utils/probe_server.rb', line 79 def next_job_id @current_job_id += 1 end |
#server_shutdown ⇒ Object
107 108 109 110 |
# File 'lib/utils/probe_server.rb', line 107 def server_shutdown "Server was shutdown down – HARD!", :type => :warn exit! 23 end |