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 ].freeze
- 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" }.freeze
Instance Method Summary collapse
-
#connection_pool(options = {}, &block) ⇒ ::ConnectionPool
Fetch the ::ConnectionPool of Rubykiq::Connections.
-
#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
38 39 40 41 42 43 |
# File 'lib/rubykiq/client.rb', line 38 def initialize( = {}) .each_pair do |key, value| send("#{key}=", value) if VALID_OPTIONS_KEYS.include?(key) end end |
Instance Method Details
#connection_pool(options = {}, &block) ⇒ ::ConnectionPool
Fetch the ::ConnectionPool of Rubykiq::Connections
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rubykiq/client.rb', line 48 def connection_pool(={}, &block) = .merge() @connection_pool ||= ::ConnectionPool.new(:timeout => redis_pool_timeout, :size => redis_pool_size) do Rubykiq::Connection.new() end if block_given? @connection_pool.with(&block) else return @connection_pool end end |
#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"]])
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rubykiq/client.rb', line 81 def push(items) raise(ArgumentError, "Message must be a Hash") unless items.is_a?(Hash) raise(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 |