Module: Sidekiq

Defined in:
lib/sidekiq.rb,
lib/sidekiq/api.rb,
lib/sidekiq/cli.rb,
lib/sidekiq/web.rb,
lib/sidekiq/util.rb,
lib/sidekiq/actor.rb,
lib/sidekiq/fetch.rb,
lib/sidekiq/rails.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/launcher.rb,
lib/sidekiq/paginator.rb,
lib/sidekiq/processor.rb,
lib/sidekiq/scheduled.rb,
lib/sidekiq/testing/inline.rb,
lib/sidekiq/middleware/chain.rb,
lib/sidekiq/redis_connection.rb,
lib/sidekiq/exception_handler.rb,
lib/sidekiq/extensions/action_mailer.rb,
lib/sidekiq/extensions/active_record.rb,
lib/sidekiq/extensions/class_methods.rb,
lib/sidekiq/extensions/generic_proxy.rb,
lib/sidekiq/middleware/server/logging.rb,
lib/sidekiq/middleware/server/retry_jobs.rb,
lib/sidekiq/middleware/server/active_record.rb

Defined Under Namespace

Modules: Actor, ExceptionHandler, Extensions, Logging, Middleware, Paginator, Scheduled, Util, Worker Classes: BasicFetch, CLI, Client, EmptyQueueError, Fetcher, Job, Launcher, Manager, Processor, Queue, Rails, RedisConnection, RetrySet, ScheduledSet, Shutdown, SortedEntry, SortedSet, Stats, Web, Workers

Constant Summary collapse

NAME =
"Sidekiq"
LICENSE =
'See LICENSE and the LGPL-3.0 for licensing details.'
DEFAULTS =
{
  :queues => [],
  :concurrency => 25,
  :require => '.',
  :environment => nil,
  :timeout => 8,
  :profile => false,
}
VERSION =
"2.13.1"

Class Method Summary collapse

Class Method Details

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

Yields:

  • (@client_chain)


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

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/0' }
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Sidekiq)

    the object that the method was called on



56
57
58
# File 'lib/sidekiq.rb', line 56

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/0' }
  config.server_middleware do |chain|
    chain.add MyServerHook
  end
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Sidekiq)

    the object that the method was called on



46
47
48
# File 'lib/sidekiq.rb', line 46

def self.configure_server
  yield self if server?
end

.dump_json(object) ⇒ Object



96
97
98
# File 'lib/sidekiq.rb', line 96

def self.dump_json(object)
  JSON.generate(object)
end

.hook_rails!Object



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

def self.hook_rails!
  if defined?(::ActiveRecord)
    ::ActiveRecord::Base.send(:include, Sidekiq::Extensions::ActiveRecord)
  end

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

.load_json(string) ⇒ Object



92
93
94
# File 'lib/sidekiq.rb', line 92

def self.load_json(string)
  JSON.parse(string)
end

.loggerObject



100
101
102
# File 'lib/sidekiq.rb', line 100

def self.logger
  Sidekiq::Logging.logger
end

.logger=(log) ⇒ Object



104
105
106
# File 'lib/sidekiq.rb', line 104

def self.logger=(log)
  Sidekiq::Logging.logger = log
end

.optionsObject



29
30
31
# File 'lib/sidekiq.rb', line 29

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

.options=(opts) ⇒ Object



33
34
35
# File 'lib/sidekiq.rb', line 33

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

.poll_interval=(interval) ⇒ Object



108
109
110
# File 'lib/sidekiq.rb', line 108

def self.poll_interval=(interval)
  self.options[:poll_interval] = interval
end

.redis(&block) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
# File 'lib/sidekiq.rb', line 64

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

.redis=(hash) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/sidekiq.rb', line 70

def self.redis=(hash)
  return @redis = hash if hash.is_a?(ConnectionPool)

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

.server?Boolean

Returns:

  • (Boolean)


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

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

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

Yields:

  • (@server_chain)


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

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

.❨╯°□°❩╯︵┻━┻Object



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

def self.❨╯°□°❩╯︵┻━┻
  puts "Calm down, bro"
end