2012-01-22 19:01:46 -05:00
|
|
|
require 'sidekiq/version'
|
|
|
|
require 'sidekiq/client'
|
2012-01-25 16:32:51 -05:00
|
|
|
require 'sidekiq/worker'
|
2012-02-09 23:32:59 -05:00
|
|
|
require 'sidekiq/rails' if defined?(::Rails)
|
2012-02-18 15:12:05 -05:00
|
|
|
require 'sidekiq/redis_connection'
|
2012-02-17 16:39:36 -05:00
|
|
|
|
2012-02-19 16:02:32 -05:00
|
|
|
require 'sidekiq/extensions/action_mailer' if defined?(::ActionMailer)
|
|
|
|
require 'sidekiq/extensions/active_record' if defined?(::ActiveRecord)
|
2012-02-18 15:12:05 -05:00
|
|
|
|
2012-02-17 16:39:36 -05:00
|
|
|
module Sidekiq
|
2012-02-18 15:12:05 -05:00
|
|
|
|
2012-02-19 16:02:32 -05:00
|
|
|
DEFAULTS = {
|
|
|
|
:queues => [],
|
|
|
|
:concurrency => 25,
|
|
|
|
:require => '.',
|
|
|
|
:environment => nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
def self.options
|
|
|
|
@options ||= DEFAULTS.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.options=(opts)
|
|
|
|
@options = opts
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2012-02-20 12:46:28 -05:00
|
|
|
# Configuration for Sidekiq server, use like:
|
2012-02-19 16:02:32 -05:00
|
|
|
#
|
2012-02-20 12:46:28 -05:00
|
|
|
# Sidekiq.configure_server do |config|
|
2012-03-06 16:42:30 -05:00
|
|
|
# config.redis = { :namespace => 'myapp', :size => 25, :url => 'redis://myhost:8877/mydb' }
|
2012-02-19 16:02:32 -05:00
|
|
|
# config.server_middleware do |chain|
|
|
|
|
# chain.add MyServerHook
|
|
|
|
# end
|
|
|
|
# end
|
2012-02-20 12:46:28 -05:00
|
|
|
def self.configure_server
|
|
|
|
yield self if server?
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Configuration for Sidekiq client, use like:
|
|
|
|
#
|
|
|
|
# Sidekiq.configure_client do |config|
|
2012-03-06 16:42:30 -05:00
|
|
|
# config.redis = { :namespace => 'myapp', :size => 1, :url => 'redis://myhost:8877/mydb' }
|
2012-02-20 12:46:28 -05:00
|
|
|
# end
|
|
|
|
def self.configure_client
|
|
|
|
yield self unless server?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.server?
|
|
|
|
defined?(Sidekiq::CLI)
|
2012-02-19 16:02:32 -05:00
|
|
|
end
|
|
|
|
|
2012-02-17 16:51:46 -05:00
|
|
|
def self.redis
|
|
|
|
@redis ||= Sidekiq::RedisConnection.create
|
|
|
|
end
|
2012-02-18 15:12:05 -05:00
|
|
|
|
2012-03-01 16:41:12 -05:00
|
|
|
def self.redis=(hash)
|
2012-03-06 16:42:30 -05:00
|
|
|
@redis = if hash.is_a?(Hash)
|
|
|
|
RedisConnection.create(hash)
|
|
|
|
else
|
2012-03-01 16:41:12 -05:00
|
|
|
puts "*****************************************************
|
|
|
|
Sidekiq.redis now takes a Hash:
|
|
|
|
old: Sidekiq.redis = Sidekiq::RedisConnection.create(:url => 'redis://foo.com', :namespace => 'abc', :size => 12)
|
|
|
|
new: Sidekiq.redis = { :url => 'redis://foo.com', :namespace => 'xyz', :size => 12 }
|
|
|
|
Called from #{caller[0]}
|
|
|
|
*****************************************************"
|
2012-03-06 16:42:30 -05:00
|
|
|
hash
|
2012-03-01 16:41:12 -05:00
|
|
|
end
|
2012-02-17 16:39:36 -05:00
|
|
|
end
|
2012-02-18 15:12:05 -05:00
|
|
|
|
|
|
|
def self.client_middleware
|
2012-02-19 16:02:32 -05:00
|
|
|
@client_chain ||= Client.default_middleware
|
2012-02-18 15:12:05 -05:00
|
|
|
yield @client_chain if block_given?
|
|
|
|
@client_chain
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.server_middleware
|
2012-02-19 16:02:32 -05:00
|
|
|
@server_chain ||= Processor.default_middleware
|
2012-02-18 15:12:05 -05:00
|
|
|
yield @server_chain if block_given?
|
|
|
|
@server_chain
|
|
|
|
end
|
|
|
|
|
2012-02-17 16:39:36 -05:00
|
|
|
end
|