Module: BlueGreenProcess

Defined in:
lib/blue_green_process.rb,
lib/blue_green_process/config.rb,
lib/blue_green_process/version.rb,
lib/blue_green_process/base_worker.rb,
lib/blue_green_process/performance.rb,
lib/blue_green_process/master_process.rb,
lib/blue_green_process/worker_process.rb,
lib/blue_green_process/shared_variable.rb

Defined Under Namespace

Classes: BaseWorker, Config, ErrorWrapper, MasterProcess, Performance, SharedVariable, WorkerProcess

Constant Summary collapse

PID_PATH =
"/tmp/pbm_blue_green_process_pids"
PROCESS_STATUS_ACTIVE =
:active
PROCESS_STATUS_INACTIVE =
:inactive
PROCESS_COMMAND_DIE =
"die"
PROCESS_COMMAND_BE_ACTIVE =
"be_active"
PROCESS_COMMAND_BE_INACTIVE =
"be_inactive"
PROCESS_COMMAND_WORK =
"work"
RESPONSE_OK =
"OK"
RESPONSE_ERROR =
"ERR"
VERSION =
"0.1.4.3"

Class Method Summary collapse

Class Method Details

.config ⇒ Object



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

def self.config
  @config ||= Config.new
end

.configure {|@config| ... } ⇒ Object

Yields:



35
36
37
38
39
# File 'lib/blue_green_process.rb', line 35

def self.configure
  @config = Config.new
  yield(@config)
  true
end

.logger ⇒ Object



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

def self.logger
  config.logger
end

.new(worker_instance:, max_work:) ⇒ Object



29
30
31
32
33
# File 'lib/blue_green_process.rb', line 29

def self.new(worker_instance:, max_work:)
  master_process = BlueGreenProcess::MasterProcess.new(worker_instance: worker_instance, max_work: max_work)
  File.write(PID_PATH, master_process.worker_pids.join(","))
  master_process
end

.performance ⇒ Object



49
50
51
# File 'lib/blue_green_process.rb', line 49

def self.performance
  @performance ||= Performance.new
end

.reset ⇒ Object



53
54
55
56
# File 'lib/blue_green_process.rb', line 53

def self.reset
  @config = Config.new
  @performance = Performance.new
end

.terminate_workers_immediately ⇒ void

This method returns an undefined value.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/blue_green_process.rb', line 59

def self.terminate_workers_immediately
  BlueGreenProcess.logger.warn "[BLUE_GREEN_PROCESS][#{$PROCESS_ID}] TERMシグナルを送信します"

  worker_pids = nil
  begin
    worker_pids = File.read(PID_PATH).split(",").map(&:to_i)
  rescue Errno::ENOENT
    BlueGreenProcess.logger.warn("[BLUE_GREEN_PROCESS] #{PID_PATH}にファイルがありませんでした")
    return
  end

  worker_pids.each do |worker_pid|
    Process.kill "TERM", worker_pid
  rescue Errno::ESRCH => e
    BlueGreenProcess.logger.warn("[BLUE_GREEN_PROCESS][#{$PROCESS_ID}] workerプロセス(#{worker_pid})の終了に失敗しました。#{e.message}")
  end
  BlueGreenProcess.logger.warn "[BLUE_GREEN_PROCESS][#{$PROCESS_ID}] workerプロセスへTERMシグナルを送信しました"
  Process.waitall
  BlueGreenProcess.logger.warn "[BLUE_GREEN_PROCESS][#{$PROCESS_ID}] workerプロセスが終了しました"
ensure
  FileUtils.rm_rf(BlueGreenProcess::PID_PATH)
end