Module: ProconBypassMan::CanOverProcess

Included in:
Background::JobQueue, Procon::PerformanceMeasurement::QueueOverProcess, RemoteAction::QueueOverProcess
Defined in:
lib/procon_bypass_man/support/can_over_process.rb

Overview

NOTE マスタープロセスでstart_distributed_object!をコールする必要がある

forkをしたらそのさきでDRb.start_serviceをコールする必要がある

Constant Summary collapse

PROTOCOL =
"drbunix".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object



8
9
10
# File 'lib/procon_bypass_man/support/can_over_process.rb', line 8

def self.extended(mod)
  mod.singleton_class.attr_accessor :drb_server, :drb_server_thread
end

Instance Method Details

#distributed_classany

Returns:

  • (any)

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/procon_bypass_man/support/can_over_process.rb', line 52

def distributed_class
  raise NotImplementedError
end

#enable?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/procon_bypass_man/support/can_over_process.rb', line 42

def enable?
  raise NotImplementedError
end

#shutdown_distributed_objectvoid Also known as: shutdown

This method returns an undefined value.



32
33
34
35
36
37
38
# File 'lib/procon_bypass_man/support/can_over_process.rb', line 32

def shutdown_distributed_object
  if self.drb_server
    self.drb_server_thread&.kill
    self.drb_server_thread = nil
    self.drb_server.stop_service
  end
end

#socket_file_pathString

Returns:

  • (String)

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/procon_bypass_man/support/can_over_process.rb', line 47

def socket_file_path
  raise NotImplementedError
end

#socket_pathString

Returns:

  • (String)


57
58
59
# File 'lib/procon_bypass_man/support/can_over_process.rb', line 57

def socket_path
  "#{PROTOCOL}:#{socket_file_path}".freeze
end

#start_distributed_object!void Also known as: start!

This method returns an undefined value.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/procon_bypass_man/support/can_over_process.rb', line 13

def start_distributed_object!
  return unless enable?

  FileUtils.rm_rf(socket_file_path) if File.exist?(socket_file_path)
  begin
    self.drb_server = DRb.start_service(socket_path, distributed_class.new, safe_level: 1)
  rescue Errno::EADDRINUSE => e
    ProconBypassMan.logger.error e
    raise
  end

  self.drb_server_thread =
    Thread.new do
      DRb.thread.join
    end
end