class Sidekiq::Client
- Sidekiq::Client
- Reference
- Object
Defined in:
sidekiq/client.crConstant Summary
-
DEFAULT_MIDDLEWARE =
Sidekiq::Middleware::Chain(Sidekiq::Middleware::ClientEntry).new
Constructors
-
.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.)
Class Method Summary
Instance Method Summary
- #atomic_push(conn, payloads)
- #middleware(&)
- #middleware : Sidekiq::Middleware::Chain(Sidekiq::Middleware::ClientEntry)
- #push(job : Sidekiq::Job)
- #push_bulk(job : Sidekiq::Job, allargs : Array(String))
- #raw_push(payloads)
Constructor Detail
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).
Class Method Detail
Instance Method Detail
Define client-side middleware:
client = Sidekiq::Client.new client.middleware do |chain| chain.use MyClientMiddleware end
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'])
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.