module Patriot::Worker

namespace for workers

Constants

DEFAULT_FETCH_CYCLE

default fetch cycle for getting job tickets in minutes

DEFAULT_FETCH_LIMIT

default limit of the number of jobs fetched at once

DEFAULT_WORKER_NAME

default worker name (for logging)

JOB_ID_IN_EXECUTION

name of thread local variable for job_id executed by the thread

SIGNAL_FOR_GRACEFUL_SHUTDOWN

SIGNAL used for graceful shutdown

SIGNAL_FOR_THREAD_DUMP

SIGNAL used for getting thread dump

Public Class Methods

get_pid(config) click to toggle source
# File lib/patriot/worker/base.rb, line 7
def get_pid(config)
  pid_file = get_pid_file(config)
  return nil unless File.exists?(pid_file)
  pid = nil
  File.open(pid_file,'r'){|f| pid = f.read.strip.to_i }
  begin
    Process.getpgid(pid)
  rescue Errno::ESRCH
    @logger.warn("process #{pid} not exist but pid file remains") if @logger
    return nil
  end
  return pid
end
get_pid_file(config) click to toggle source
# File lib/patriot/worker/base.rb, line 22
def get_pid_file(config)
  worker_name = config.get('worker_name', Patriot::Worker::DEFAULT_WORKER_NAME)
  return File.join($home, 'run', "patriot-worker_#{worker_name}.pid")
end

Private Instance Methods

get_pid(config) click to toggle source
# File lib/patriot/worker/base.rb, line 7
def get_pid(config)
  pid_file = get_pid_file(config)
  return nil unless File.exists?(pid_file)
  pid = nil
  File.open(pid_file,'r'){|f| pid = f.read.strip.to_i }
  begin
    Process.getpgid(pid)
  rescue Errno::ESRCH
    @logger.warn("process #{pid} not exist but pid file remains") if @logger
    return nil
  end
  return pid
end
get_pid_file(config) click to toggle source
# File lib/patriot/worker/base.rb, line 22
def get_pid_file(config)
  worker_name = config.get('worker_name', Patriot::Worker::DEFAULT_WORKER_NAME)
  return File.join($home, 'run', "patriot-worker_#{worker_name}.pid")
end