class Sidekiq::Client

Defined in:

sidekiq/client.cr

Constant Summary

DEFAULT_MIDDLEWARE = Sidekiq::Middleware::Chain(Sidekiq::Middleware::ClientEntry).new

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(pool = nil) #

Sidekiq::Client normally uses the default Redis pool but you may set a custom ConnectionPool if you want to shard your Sidekiq jobs across several Redis instances (for scalability reasons, e.g.)

c = Sidekiq::Client.new(Sidekiq::Pool.new)

Generally this is only needed for very large Sidekiq installs processing thousands of jobs per second. I don't recommend sharding unless you cannot scale any other way (e.g. splitting your app into smaller apps).


[View source]

Class Method Detail

def self.default_context : Sidekiq::Context #

[View source]
def self.default_context=(ctx : Sidekiq::Context | Nil) #

[View source]
def self.middleware #

[View source]

Instance Method Detail

def atomic_push(conn, payloads) #

[View source]
def middleware(&) #

Define client-side middleware:

client = Sidekiq::Client.new client.middleware do |chain| chain.use MyClientMiddleware end


[View source]

[View source]
def push(job : Sidekiq::Job) #

The main method used to push a job to Redis. Accepts a number of options:

queue - the named queue to use, default 'default' class - the worker class to call, required args - an array of simple arguments to the perform method, must be JSON-serializable retry - whether to retry this job if it fails, default true or an integer number of retries backtrace - whether to save any error backtrace, default false

All options must be strings, not symbols. NB: because we are serializing to JSON, all symbols in 'args' will be converted to strings. Note that +backtrace: true+ can take quite a bit of space in Redis; a large volume of failing jobs can start Redis swapping if you aren't careful.

Returns a unique Job ID. If middleware stops the job, nil will be returned instead.

Example: push('queue' => 'my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar'])


[View source]
def push_bulk(job : Sidekiq::Job, allargs : Array(String)) #

Push a large number of jobs to Redis. In practice this method is only useful if you are pushing thousands of jobs or more. This method cuts out the redis network round trip latency.

Takes the same arguments as #push except that allargs is expected to be an Array of Arrays. All other keys are duplicated for each job. Each job is run through the client middleware pipeline and each job gets its own Job ID as normal.

Returns an array of the of pushed jobs' jids. The number of jobs pushed can be less than the number given if the middleware stopped processing for one or more jobs.


[View source]
def raw_push(payloads) #

[View source]