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

126 lines
2.7 KiB
Ruby
Raw Normal View History

2013-02-08 16:10:21 -05:00
# encoding: utf-8
2012-01-22 19:01:46 -05:00
require 'sidekiq/version'
require 'sidekiq/logging'
2012-01-22 19:01:46 -05:00
require 'sidekiq/client'
require 'sidekiq/worker'
require 'sidekiq/redis_connection'
2012-03-17 12:41:24 -04:00
require 'sidekiq/util'
require 'sidekiq/api'
2012-02-17 16:39:36 -05:00
2013-05-12 17:33:49 -04:00
require 'json'
2012-02-17 16:39:36 -05:00
module Sidekiq
2012-09-09 15:41:23 -04:00
NAME = "Sidekiq"
2012-09-03 14:34:07 -04:00
LICENSE = 'See LICENSE and the LGPL-3.0 for licensing details.'
DEFAULTS = {
:queues => [],
:concurrency => 25,
:require => '.',
:environment => nil,
:timeout => 8,
2013-01-27 17:03:40 -05:00
:profile => false,
}
def self.°°
2013-02-08 15:42:06 -05:00
puts "Calm down, bro"
end
def self.options
@options ||= DEFAULTS.dup
end
def self.options=(opts)
@options = opts
end
##
# Configuration for Sidekiq server, use like:
#
# Sidekiq.configure_server do |config|
# config.redis = { :namespace => 'myapp', :size => 25, :url => 'redis://myhost:8877/0' }
# config.server_middleware do |chain|
# chain.add MyServerHook
# end
# end
def self.configure_server
yield self if server?
end
##
# Configuration for Sidekiq client, use like:
#
# Sidekiq.configure_client do |config|
# config.redis = { :namespace => 'myapp', :size => 1, :url => 'redis://myhost:8877/0' }
# end
def self.configure_client
yield self unless server?
end
def self.server?
defined?(Sidekiq::CLI)
end
def self.redis(&block)
2012-03-28 22:16:54 -04:00
raise ArgumentError, "requires a block" if !block
@redis ||= Sidekiq::RedisConnection.create(@hash || {})
2012-03-28 22:16:54 -04:00
@redis.with(&block)
end
def self.redis=(hash)
return @redis = hash if hash.is_a?(ConnectionPool)
2012-03-28 22:16:54 -04:00
if hash.is_a?(Hash)
@hash = hash
else
raise ArgumentError, "redis= requires a Hash or ConnectionPool"
end
2012-02-17 16:39:36 -05:00
end
2013-10-24 00:58:15 -04:00
def self.client_middleware
@client_chain ||= Middleware::Chain.new
yield @client_chain if block_given?
@client_chain
end
def self.server_middleware
@server_chain ||= Processor.default_middleware
yield @server_chain if block_given?
@server_chain
end
2013-09-07 12:54:13 -04:00
def self.default_worker_options=(hash)
@default_worker_options = default_worker_options.merge(hash)
end
def self.default_worker_options
@default_worker_options || { 'retry' => true, 'queue' => 'default' }
end
2012-04-22 22:22:09 -04:00
def self.load_json(string)
2013-05-12 17:33:49 -04:00
JSON.parse(string)
end
2012-04-22 22:22:09 -04:00
def self.dump_json(object)
2013-05-12 17:33:49 -04:00
JSON.generate(object)
end
def self.logger
Sidekiq::Logging.logger
end
2012-06-26 12:01:54 -04:00
def self.logger=(log)
Sidekiq::Logging.logger = log
end
2012-06-19 19:36:59 -04:00
def self.poll_interval=(interval)
self.options[:poll_interval] = interval
end
2012-02-17 16:39:36 -05:00
end
require 'sidekiq/extensions/class_methods'
require 'sidekiq/extensions/action_mailer'
require 'sidekiq/extensions/active_record'
require 'sidekiq/rails' if defined?(::Rails::Engine)