mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Remove daemonization code, let god/monit handle it.
Use a 'default' queue for simplicity.
This commit is contained in:
parent
da8c837e98
commit
e8b8e53175
2 changed files with 8 additions and 32 deletions
|
@ -16,8 +16,6 @@ module Sidekiq
|
||||||
FOREVER = 2_000_000_000
|
FOREVER = 2_000_000_000
|
||||||
|
|
||||||
def run
|
def run
|
||||||
write_pid if @options[:daemon]
|
|
||||||
|
|
||||||
::Sidekiq::Client.redis = ConnectionPool.new { Redis.connect(:url => @options[:server]) }
|
::Sidekiq::Client.redis = ConnectionPool.new { Redis.connect(:url => @options[:server]) }
|
||||||
server = Sidekiq::Server.new(@options[:server], @options)
|
server = Sidekiq::Server.new(@options[:server], @options)
|
||||||
begin
|
begin
|
||||||
|
@ -34,18 +32,13 @@ module Sidekiq
|
||||||
private
|
private
|
||||||
|
|
||||||
def boot_rails
|
def boot_rails
|
||||||
ENV['RAILS_ENV'] = @options[:environment] || 'production'
|
ENV['RAILS_ENV'] = @options[:environment]
|
||||||
require File.expand_path("#{@options[:rails]}/config/environment.rb")
|
require File.expand_path("#{@options[:rails]}/config/environment.rb")
|
||||||
Rails.application.eager_load!
|
Rails.application.eager_load!
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate!
|
def validate!
|
||||||
$DEBUG = @options[:verbose]
|
$DEBUG = @options[:verbose]
|
||||||
if @options[:queues].size == 0
|
|
||||||
log "========== Please configure at least one queue to process =========="
|
|
||||||
log @parser
|
|
||||||
exit(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
if !File.exist?("#{@options[:rails]}/config/boot.rb")
|
if !File.exist?("#{@options[:rails]}/config/boot.rb")
|
||||||
log "========== Please point sidekiq to a Rails 3 application =========="
|
log "========== Please point sidekiq to a Rails 3 application =========="
|
||||||
|
@ -56,12 +49,10 @@ module Sidekiq
|
||||||
|
|
||||||
def parse_options(argv=ARGV)
|
def parse_options(argv=ARGV)
|
||||||
@options = {
|
@options = {
|
||||||
:daemon => false,
|
|
||||||
:verbose => false,
|
:verbose => false,
|
||||||
:queues => [],
|
:queues => ['default'],
|
||||||
:worker_count => 25,
|
:worker_count => 25,
|
||||||
:server => 'redis://localhost:6379/0',
|
:server => 'redis://localhost:6379/0',
|
||||||
:pidfile => nil,
|
|
||||||
:rails => '.',
|
:rails => '.',
|
||||||
:environment => 'production',
|
:environment => 'production',
|
||||||
}
|
}
|
||||||
|
@ -74,14 +65,6 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
o.on "-d", "Daemonize" do |arg|
|
|
||||||
@options[:daemon] = arg
|
|
||||||
end
|
|
||||||
|
|
||||||
o.on "--pidfile PATH", "Use PATH as a pidfile" do |arg|
|
|
||||||
@options[:pidfile] = arg
|
|
||||||
end
|
|
||||||
|
|
||||||
o.on "-v", "--verbose", "Print more verbose output" do
|
o.on "-v", "--verbose", "Print more verbose output" do
|
||||||
@options[:verbose] = true
|
@options[:verbose] = true
|
||||||
end
|
end
|
||||||
|
@ -103,7 +86,7 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@parser.banner = "sidekiq -q foo -q bar <more options>"
|
@parser.banner = "sidekiq [options]"
|
||||||
@parser.on_tail "-h", "--help", "Show help" do
|
@parser.on_tail "-h", "--help", "Show help" do
|
||||||
log @parser
|
log @parser
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -111,13 +94,5 @@ module Sidekiq
|
||||||
@parser.parse!(argv)
|
@parser.parse!(argv)
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_pid
|
|
||||||
if path = @options[:pidfile]
|
|
||||||
File.open(path, "w") do |f|
|
|
||||||
f.puts Process.pid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,8 +14,8 @@ module Sidekiq
|
||||||
|
|
||||||
# Example usage:
|
# Example usage:
|
||||||
# Sidekiq::Client.push('my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar'])
|
# Sidekiq::Client.push('my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar'])
|
||||||
def self.push(queue, item)
|
def self.push(queue='default', item)
|
||||||
raise(ArgumentError, "Message must be a Hash of the form: { :class => SomeClass, :args => ['bob', 1, :foo => 'bar'] }") unless item.is_a?(Hash)
|
raise(ArgumentError, "Message must be a Hash of the form: { 'class' => SomeClass, 'args' => ['bob', 1, :foo => 'bar'] }") unless item.is_a?(Hash)
|
||||||
raise(ArgumentError, "Message must include a class and set of arguments: #{item.inspect}") if !item['class'] || !item['args']
|
raise(ArgumentError, "Message must include a class and set of arguments: #{item.inspect}") if !item['class'] || !item['args']
|
||||||
|
|
||||||
item['class'] = item['class'].to_s if !item['class'].is_a?(String)
|
item['class'] = item['class'].to_s if !item['class'].is_a?(String)
|
||||||
|
@ -28,14 +28,15 @@ module Sidekiq
|
||||||
#
|
#
|
||||||
# Sidekiq::Client.enqueue(MyWorker, 'foo', 1, :bat => 'bar')
|
# Sidekiq::Client.enqueue(MyWorker, 'foo', 1, :bat => 'bar')
|
||||||
#
|
#
|
||||||
# where MyWorker has defined:
|
# Messages are enqueued to the 'default' queue. Optionally,
|
||||||
|
# MyWorker can define a queue class method:
|
||||||
#
|
#
|
||||||
# def self.queue
|
# def self.queue
|
||||||
# 'my_queue'
|
# 'my_queue'
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def self.enqueue(klass, *args)
|
def self.enqueue(klass, *args)
|
||||||
queue = (klass.respond_to?(:queue) && klass.queue) || klass.instance_variable_get(:@queue) || raise(ArgumentError, "Cannot determine queue to use")
|
queue = (klass.respond_to?(:queue) && klass.queue) || 'default'
|
||||||
push(queue, { 'class' => klass.name, 'args' => args })
|
push(queue, { 'class' => klass.name, 'args' => args })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue