Navigation Menu

Skip to content

Commit

Permalink
Support graceful shutdown
Browse files Browse the repository at this point in the history
It requires groonga 3.0.5 and rroonga 3.0.3. They are not released
yet.
  • Loading branch information
kou committed Jun 14, 2013
1 parent f938dea commit 243437e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fluent-plugin-droonga.gemspec
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.add_dependency "fluentd"
gem.add_dependency "rroonga"
gem.add_dependency "rroonga", ">= 3.0.3"
gem.add_dependency "fluent-logger"
gem.add_development_dependency "rake"
gem.add_development_dependency "bundler"
Expand Down
23 changes: 19 additions & 4 deletions lib/droonga/worker.rb
Expand Up @@ -42,10 +42,7 @@ def initialize(options={})
end

def shutdown
@pool.each do |pid|
# TODO: do it gracefully
Process.kill(:KILL, pid)
end
shutdown_workers
@handlers.each do |handler|
handler.shutdown
end
Expand Down Expand Up @@ -76,6 +73,24 @@ def post(body, destination=nil)
end

private
def shutdown_workers
@pool.each do |pid|
Process.kill(:TERM, pid)
end
queue = @context[@queue_name]
3.times do |i|
break if @pool.empty?
queue.unblock
@pool.reject! do |pid|
not Process.waitpid(pid, Process::WNOHANG).nil?
end
sleep(i ** 2 * 0.1)
end
@pool.each do |pid|
Process.kill(:KILL, pid)
end
end

def post_or_push(message, body, destination)
route = nil
unless destination
Expand Down

0 comments on commit 243437e

Please sign in to comment.