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.



24
25
26
27
28
# File 'lib/utils/probe_server.rb', line 24

def initialize
  @jobs_queue = Queue.new
  @current_job_id = 0
  Thread.new { work_loop }
end

Instance Method Details

#clear_jobsObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/utils/probe_server.rb', line 58

def clear_jobs
  queue_synchronize do
    unless @jobs_queue.empty?
      @jobs_queue.clear
      output_message "Cleared all queued jobs.", :type => :warn
      true
    else
      false
    end
  end
end

#continueObject



45
46
47
# File 'lib/utils/probe_server.rb', line 45

def continue
  @pid and Process.kill :CONT, @pid
end

#enqueue(job_args) ⇒ Object Also known as: run



34
35
36
37
38
# File 'lib/utils/probe_server.rb', line 34

def enqueue(job_args)
  job = Job.new(self, job_args)
  output_message "#{job.inspect} enqueued."
  @jobs_queue.push job
end

#list_jobsObject



54
55
56
# File 'lib/utils/probe_server.rb', line 54

def list_jobs
  @jobs_queue.instance_variable_get(:@que)
end

#next_job_idObject



30
31
32
# File 'lib/utils/probe_server.rb', line 30

def next_job_id
  @current_job_id += 1
end

#shutdownObject



49
50
51
52
# File 'lib/utils/probe_server.rb', line 49

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

#stopObject



41
42
43
# File 'lib/utils/probe_server.rb', line 41

def stop
  @pid and Process.kill :STOP, @pid
end