Class: Droonga::Supervisor::WorkerRunner

Inherits:
Object
  • Object
show all
Includes:
Deferrable, Loggable
Defined in:
lib/droonga/supervisor.rb

Instance Method Summary collapse

Methods included from Deferrable

#wait_until_ready

Constructor Details

#initialize(loop, id, config) ⇒ WorkerRunner

Returns a new instance of WorkerRunner.



102
103
104
105
106
107
# File 'lib/droonga/supervisor.rb', line 102

def initialize(loop, id, config)
  @loop = loop
  @id = id
  @config = config
  @stop_gracefully_callback = nil
end

Instance Method Details

#refresh_node_referenceObject



153
154
155
# File 'lib/droonga/supervisor.rb', line 153

def refresh_node_reference
  @supervisor.refresh_node_reference
end

#startObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/droonga/supervisor.rb', line 109

def start
  control_write_in, control_write_out = IO.pipe
  control_read_in, control_read_out = IO.pipe
  env = {}
  command_line = [
    RbConfig.ruby,
    "-S",
    "droonga-engine-worker",
    "--control-read-fd", control_write_in.fileno.to_s,
    "--control-write-fd", control_read_out.fileno.to_s,
    "--job-queue-socket-path", @config.job_pusher.socket_path.to_s,
    "--pid-file", pid_path.to_s,
    "--label", @config.label,
    "--dataset", @config.dataset.name,
    "--database-path", @config.database_path.to_s,
    "--plugins", @config.plugins.join(","),
    "--internal-connection-lifetime",
      @config.internal_connection_lifetime.to_s,
  ]
  options = {
    control_write_in => control_write_in,
    control_read_out => control_read_out,
  }
  @pid = spawn(env, *command_line, options)
  control_write_in.close
  control_read_out.close
  @supervisor = create_process_supervisor(control_read_in,
                                          control_write_out)
  @supervisor.start
end

#stop_gracefully(&block) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/droonga/supervisor.rb', line 140

def stop_gracefully(&block)
  logger.trace("stop_gracefully: start")
  @supervisor.stop_gracefully
  @stop_gracefully_callback = lambda do
    yield if block_given?
    logger.trace("stop_gracefully: done")
  end
end

#stop_immediatelyObject



149
150
151
# File 'lib/droonga/supervisor.rb', line 149

def stop_immediately
  @supervisor.stop_immediately
end

#success?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/droonga/supervisor.rb', line 157

def success?
  @success
end