Class: Utils::ProbeServer

Inherits:
Object show all
Defined in:
lib/utils/probe_server.rb

Defined Under Namespace

Classes: Job

Instance Method Summary collapse

Constructor Details

#initializeProbeServer

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

#docsObject



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

#envObject



153
154
155
# File 'lib/utils/probe_server.rb', line 153

def env
  ENV
end

#history_clearObject



147
148
149
150
# File 'lib/utils/probe_server.rb', line 147

def history_clear
  @history = []
  true
end

#history_listObject



142
143
144
# File 'lib/utils/probe_server.rb', line 142

def history_list
  @history.dup
end

#jobObject



73
74
75
76
77
# File 'lib/utils/probe_server.rb', line 73

def job
  queue_synchronize do
    @job
  end
end

#job_continueObject



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)
  output_message "#{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_stopObject



97
98
99
# File 'lib/utils/probe_server.rb', line 97

def job_stop
  job_kill :STOP
end

#jobs_clearObject



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
      output_message "Cleared all queued jobs.", :type => :warn
      true
    else
      false
    end
  end
end

#jobs_listObject



113
114
115
# File 'lib/utils/probe_server.rb', line 113

def jobs_list
  @jobs_queue.instance_variable_get(:@que).dup
end

#next_job_idObject



79
80
81
# File 'lib/utils/probe_server.rb', line 79

def next_job_id
  @current_job_id += 1
end

#server_shutdownObject



107
108
109
110
# File 'lib/utils/probe_server.rb', line 107

def server_shutdown
  output_message "Server was shutdown down – HARD!", :type => :warn
  exit! 23
end