1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Adding pidfile option

This commit is contained in:
jc00ke 2012-02-15 10:56:36 -08:00
parent 64e72eef28
commit 0f248f3412
2 changed files with 36 additions and 0 deletions

View file

@ -29,6 +29,7 @@ module Sidekiq
def parse(args=ARGV)
Sidekiq::Util.logger
parse_options(args)
write_pid
validate!
boot_system
end
@ -127,6 +128,10 @@ module Sidekiq
o.on '-c', '--concurrency INT', "processor threads to use" do |arg|
@options[:processor_count] = arg.to_i
end
o.on '-p', '--pidfile PATH', "path to use" do |arg|
@options[:pidfile] = arg
end
end
@parser.banner = "sidekiq [options]"
@ -137,5 +142,13 @@ module Sidekiq
@parser.parse!(argv)
end
def write_pid
if path = @options[:pidfile]
File.open(path, 'w') do |f|
f.puts Process.pid
end
end
end
end
end

View file

@ -1,5 +1,6 @@
require 'helper'
require 'sidekiq/cli'
require 'tempfile'
class TestCli < MiniTest::Unit::TestCase
describe 'with cli' do
@ -34,6 +35,28 @@ class TestCli < MiniTest::Unit::TestCase
assert_equal %w(bar foo foo foo), @cli.options[:queues].sort
end
describe 'with pidfile' do
before do
@tmp_file = Tempfile.new('sidekiq-test')
@tmp_path = @tmp_file.path
@tmp_file.close!
File.unlink @tmp_path if File.exist? @tmp_path
@cli.parse(['sidekiq', '-p', @tmp_path, '-r', './test/fake_env.rb'])
end
after do
File.unlink @tmp_path if File.exist? @tmp_path
end
it 'sets pidfile path' do
assert_equal @tmp_path, @cli.options[:pidfile]
end
it 'writes pidfile' do
assert_equal File.read(@tmp_path).strip.to_i, Process.pid
end
end
def new_cli
cli = Sidekiq::CLI.new
def cli.die(code)