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/manager.rb,
lib/sidekiq/testing.rb,
lib/sidekiq/version.rb,
lib/sidekiq/processor.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/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, 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.0.0"

Class Method Summary collapse

Class Method Details

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

Yields:

  • (@client_chain)

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

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


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

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


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

def self.configure_server
  yield self if server?
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

.optionsObject


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

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

.options=(opts) ⇒ Object


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

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

.redis(&block) ⇒ Object

Raises:

  • (ArgumentError)

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

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

.redis=(hash) ⇒ Object


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

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)

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

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

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

Yields:

  • (@server_chain)

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

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