Class: Droonga::Supervisor::WorkerRunner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loop, id, config) ⇒ WorkerRunner

Returns a new instance of WorkerRunner.



93
94
95
96
97
98
99
100
# File 'lib/droonga/supervisor.rb', line 93

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

Instance Attribute Details

#on_failure=(value) ⇒ Object

Sets the attribute on_failure

Parameters:

  • value

    the value to set the attribute on_failure to.



92
93
94
# File 'lib/droonga/supervisor.rb', line 92

def on_failure=(value)
  @on_failure = value
end

#on_ready=(value) ⇒ Object

Sets the attribute on_ready

Parameters:

  • value

    the value to set the attribute on_ready to.



91
92
93
# File 'lib/droonga/supervisor.rb', line 91

def on_ready=(value)
  @on_ready = value
end

Instance Method Details

#startObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/droonga/supervisor.rb', line 102

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,
    "--dataset", @config.dataset.name,
    "--database-path", @config.database_path.to_s,
    "--plugins", @config.plugins.join(","),
  ]
  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



130
131
132
133
134
135
# File 'lib/droonga/supervisor.rb', line 130

def stop_gracefully(&block)
  logger.trace("stop_gracefully: start")
  @supervisor.stop_gracefully
  @stop_gracefully_callback = block
  logger.trace("stop_gracefully: done")
end

#stop_immediatelyObject



137
138
139
# File 'lib/droonga/supervisor.rb', line 137

def stop_immediately
  @supervisor.stop_immediately
end

#success?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/droonga/supervisor.rb', line 141

def success?
  @success
end