Module: Sidekiq

Defined in:
lib/sidekiq.rb,
lib/sidekiq/cli.rb,
lib/sidekiq/web.rb,
lib/sidekiq/util.rb,
lib/sidekiq/fetch.rb,
lib/sidekiq/rails.rb,
lib/sidekiq/retry.rb,
lib/sidekiq/client.rb,
lib/sidekiq/worker.rb,
lib/sidekiq/logging.rb,
lib/sidekiq/manager.rb,
lib/sidekiq/testing.rb,
lib/sidekiq/version.rb,
lib/sidekiq/processor.rb,
lib/sidekiq/testing/inline.rb,
lib/sidekiq/middleware/chain.rb,
lib/sidekiq/redis_connection.rb,
lib/sidekiq/extensions/action_mailer.rb,
lib/sidekiq/extensions/active_record.rb,
lib/sidekiq/extensions/generic_proxy.rb,
lib/sidekiq/middleware/server/logging.rb,
lib/sidekiq/middleware/server/timeout.rb,
lib/sidekiq/middleware/server/retry_jobs.rb,
lib/sidekiq/middleware/client/unique_jobs.rb,
lib/sidekiq/middleware/server/unique_jobs.rb,
lib/sidekiq/middleware/server/failure_jobs.rb,
lib/sidekiq/middleware/server/active_record.rb,
lib/sidekiq/middleware/server/exception_handler.rb

Defined Under Namespace

Modules: Extensions, Logging, Middleware, Retry, Util, Worker Classes: CLI, Client, Fetcher, Manager, Processor, Rails, RedisConnection, SprocketsMiddleware, Web

Constant Summary collapse

DEFAULTS =
{
  :queues => [],
  :concurrency => 25,
  :require => '.',
  :environment => nil,
  :timeout => 8,
  :enable_rails_extensions => true,
}
VERSION =
"1.2.3"

Class Method Summary collapse

Class Method Details

.client_middleware {|@client_chain| ... } ⇒ Object

Yields:

  • (@client_chain)


74
75
76
77
78
# File 'lib/sidekiq.rb', line 74

def self.client_middleware
  @client_chain ||= Client.default_middleware
  yield @client_chain if block_given?
  @client_chain
end

.configure_client {|_self| ... } ⇒ Object

Configuration for Sidekiq client, use like:

Sidekiq.configure_client do |config|
  config.redis = { :namespace => 'myapp', :size => 1, :url => 'redis://myhost:8877/mydb' }
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Sidekiq)

    the object that the method was called on



50
51
52
# File 'lib/sidekiq.rb', line 50

def self.configure_client
  yield self unless server?
end

.configure_server {|_self| ... } ⇒ Object

Configuration for Sidekiq server, use like:

Sidekiq.configure_server do |config|
  config.redis = { :namespace => 'myapp', :size => 25, :url => 'redis://myhost:8877/mydb' }
  config.server_middleware do |chain|
    chain.add MyServerHook
  end
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Sidekiq)

    the object that the method was called on



40
41
42
# File 'lib/sidekiq.rb', line 40

def self.configure_server
  yield self if server?
end

.dump_json(object) ⇒ Object



90
91
92
# File 'lib/sidekiq.rb', line 90

def self.dump_json(object)
  MultiJson.encode(object)
end

.hook_rails!Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/sidekiq/rails.rb', line 2

def self.hook_rails!
  return unless Sidekiq.options[:enable_rails_extensions]
  if defined?(ActiveRecord)
    ActiveRecord::Base.extend(Sidekiq::Extensions::ActiveRecord)
    ActiveRecord::Base.send(:include, Sidekiq::Extensions::ActiveRecord)
  end

  if defined?(ActionMailer)
    ActionMailer::Base.extend(Sidekiq::Extensions::ActionMailer)
  end
end

.load_json(string) ⇒ Object



86
87
88
# File 'lib/sidekiq.rb', line 86

def self.load_json(string)
  MultiJson.decode(string)
end

.loggerObject



94
95
96
# File 'lib/sidekiq.rb', line 94

def self.logger
  Sidekiq::Logging.logger
end

.optionsObject



23
24
25
# File 'lib/sidekiq.rb', line 23

def self.options
  @options ||= DEFAULTS.dup
end

.options=(opts) ⇒ Object



27
28
29
# File 'lib/sidekiq.rb', line 27

def self.options=(opts)
  @options = opts
end

.redis(&block) ⇒ Object

Raises:

  • (ArgumentError)


58
59
60
61
62
# File 'lib/sidekiq.rb', line 58

def self.redis(&block)
  @redis ||= Sidekiq::RedisConnection.create
  raise ArgumentError, "requires a block" if !block
  @redis.with(&block)
end

.redis=(hash) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/sidekiq.rb', line 64

def self.redis=(hash)
  if hash.is_a?(Hash)
    @redis = RedisConnection.create(hash)
  elsif hash.is_a?(ConnectionPool)
    @redis = hash
  else
    raise ArgumentError, "redis= requires a Hash or ConnectionPool"
  end
end

.server?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/sidekiq.rb', line 54

def self.server?
  defined?(Sidekiq::CLI)
end

.server_middleware {|@server_chain| ... } ⇒ Object

Yields:

  • (@server_chain)


80
81
82
83
84
# File 'lib/sidekiq.rb', line 80

def self.server_middleware
  @server_chain ||= Processor.default_middleware
  yield @server_chain if block_given?
  @server_chain
end