Class: Rubykiq::Client
- Inherits:
-
Object
- Object
- Rubykiq::Client
- Defined in:
- lib/rubykiq/client.rb
Constant Summary collapse
- VALID_OPTIONS_KEYS =
An array of valid keys in the options hash when configuring a
Rubykiq::Client
[ :redis_pool_size, :redis_pool_timeout, :url, :namespace, :driver, :retry, :queue ]
- DEFAULT_OPTIONS =
A hash of valid options and their default values
{ redis_pool_size: 1, redis_pool_timeout: 1, url: nil, namespace: nil, driver: :ruby, retry: true, queue: 'default' }
Instance Attribute Summary collapse
-
#connection_pool(options = {}, &block) ⇒ ::ConnectionPool
Fetch the ::ConnectionPool of Rubykiq::Connections.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Initialize a new Client object.
-
#push(items) ⇒ Object
(also: #<<)
Push a Sidekiq job to Redis.
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize a new Client object
40 41 42 43 44 45 |
# File 'lib/rubykiq/client.rb', line 40 def initialize( = {}) .each_pair do |key, value| send("#{key}=", value) if VALID_OPTIONS_KEYS.include?(key) end end |
Instance Attribute Details
#connection_pool(options = {}, &block) ⇒ ::ConnectionPool
Fetch the ::ConnectionPool of Rubykiq::Connections
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubykiq/client.rb', line 50 def connection_pool( = {}, &block) = .merge() initialize_connection_pool() unless defined?(@connection_pool) if block_given? @connection_pool.with(&block) else @connection_pool end end |
Instance Method Details
#push(items) ⇒ Object Also known as: <<
Push a Sidekiq job to Redis. Accepts a number of options:
:class - the worker class to call, required.
:queue - the named queue to use, optional ( default: 'default' )
:args - an array of simple arguments to the perform method, must be JSON-serializable, optional ( default: [] )
:retry - whether to retry this job if it fails, true or false, default true, optional ( default: true )
:at - when the job should be executed. This can be a Time
, Date
or any Time.parse
-able strings, optional.
Returns nil if not pushed to Redis. In the case of an indvidual job a job ID will be returned, if multiple jobs are pushed the size of the jobs will be returned
Example: Rubykiq.push(:class => 'Worker', :args => ['foo', 1, :bat => 'bar']) Rubykiq.push(:class => 'Scheduler', :queue => 'scheduler') Rubykiq.push(:class => 'DelayedMailer', :at => '2013-01-01T09:00:00Z') Rubykiq.push(:class => 'Worker', :args => [['foo'], ['bar']])
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rubykiq/client.rb', line 79 def push(items) fail(ArgumentError, 'Message must be a Hash') unless items.is_a?(Hash) fail(ArgumentError, 'Message args must be an Array') if items[:args] && !items[:args].is_a?(Array) # args are optional items[:args] ||= [] # determine if this items arg's is a nested array items[:args].first.is_a?(Array) ? push_many(items) : push_one(items) end |