Sha256: 6158fab6af46753a4037b1eda623093d0cdeb935a2bcfffc312b42404d6b2175

Contents?: true

Size: 1.38 KB

Versions: 16

Compression:

Stored size: 1.38 KB

Contents

require 'drb/drb'

# NOTE マスタープロセスでstart_distributed_object!をコールする必要がある
#      forkをしたらそのさきでDRb.start_serviceをコールする必要がある
module ProconBypassMan::CanOverProcess
  PROTOCOL = "drbunix".freeze

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

  # @return [void]
  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
  alias start! start_distributed_object!

  # @return [void]
  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
  alias shutdown shutdown_distributed_object

  # @return [Boolean]
  def enable?
    raise NotImplementedError
  end

  # @return [String]
  def socket_file_path
    raise NotImplementedError
  end

  # @return [any]
  def distributed_class
    raise NotImplementedError
  end

  # @return [String]
  def socket_path
    "#{PROTOCOL}:#{socket_file_path}".freeze
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.12 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.11 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/support/can_over_process.rb
procon_bypass_man-0.2.3 lib/procon_bypass_man/support/can_over_process.rb