class Postjob::WorkerSession
A worker worker_session
Attributes
attributes[R]
client_socket[R]
created_at[R]
host_id[R]
id[R]
queues[R]
workflows[R]
Public Class Methods
start!(workflows_with_versions, heartbeat: true, queues:)
click to toggle source
Starts a worker session.
# File lib/postjob/worker_session.rb, line 11 def start!(workflows_with_versions, heartbeat: true, queues:) host_id = ::Postjob.host_id worker_session = ::Postjob::Queue.worker_session_start(workflows_with_versions, host_id: host_id, queues: queues) Postjob.logger.info "Starting worker_session #{worker_session.inspect}, on pid #{$$}" start_heartbeat_monitor(host_id) if heartbeat worker_session end
start_heartbeat_monitor(host_id)
click to toggle source
Starts a heartbeat monitor in the background (i.e. in a new thread).
# File lib/postjob/worker_session.rb, line 26 def start_heartbeat_monitor(host_id) Thread.new do begin Simple::SQL.connect! run_heartbeat_monitor(host_id) rescue Exception => e STDERR.puts "#{e}, from \n\t#{e.backtrace[0, 5].join("\n\t")}" end end end
stop!(worker_session)
click to toggle source
# File lib/postjob/worker_session.rb, line 21 def stop!(worker_session) ::Postjob::Queue.worker_session_stop(worker_session.id) end
Private Class Methods
run_heartbeat_monitor(host_id) { || ... }
click to toggle source
This message is used during specs.
# File lib/postjob/worker_session.rb, line 40 def run_heartbeat_monitor(host_id, &block) Heartbeat.monitor(60) do |measurement| Postjob::Queue.host_heartbeat(host_id, measurement) next true unless block yield end end
Public Instance Methods
inspect()
click to toggle source
# File lib/postjob/worker_session.rb, line 61 def inspect # [TODO] - grepping workflows by /\d$/ to only count workflows with a version number is a bit hackish. workflow_count = self.workflows.grep(/\d$/) queues = self.queues.map(&:inspect).join(", ") "<Session##{id} w/host_id: #{host_id}, queues: #{queues}, client_socket: #{client_socket}, #{workflow_count} workflows>" end
to_s()
click to toggle source
# File lib/postjob/worker_session.rb, line 57 def to_s "Session##{id}" end