module Cyclop
Constants
- VERSION
Public Instance Methods
db()
click to toggle source
Get ‘Mongo::DB` to use
# File lib/cyclop.rb, line 26 def db @db end
db=(db)
click to toggle source
Set which ‘Mongo::DB` to use
# File lib/cyclop.rb, line 21 def db=(db) @db = db end
failed(*args)
click to toggle source
Get failed ‘Cyclop::Job`s
Parameters:
* (Symbol, String) queues - list of queues to get a `Cyclop::Job` from. Defaults to all. * (Hash) opts (defaults to: {}) - a customizable set of options.
Options Hash (opts):
* (String) :host - limit to `Cyclop::Job`s queued by this host. * (Integer) :skip (0) - number of `Cyclop::Job`s to skip. * (Integer) :limit (nil) - maximum number of `Cyclop::Job`s to return.
Returns an ‘Array` of failed `Cyclop::Job`
# File lib/cyclop.rb, line 122 def failed(*args) opts = extract_opts! args Cyclop::Job.failed({queues: args}.merge opts) end
host()
click to toggle source
Get memoized host
# File lib/cyclop.rb, line 31 def host @host ||= Socket.gethostname end
master_id()
click to toggle source
Get a unique identifier for current process
# File lib/cyclop.rb, line 36 def master_id @master_id ||= "#{host}-#{Process.pid}-#{Thread.current}" end
next(*args)
click to toggle source
Get a ‘Cyclop::Job` to process
Parameters:
* (Symbol, String) queues - list of queues to get a `Cyclop::Job` from. Defaults to all. * (Hash) opts (defaults to: {}) - a customizable set of options.
Options Hash (opts):
* (String) :host - limit to `Cyclop::Job`s queued by this host.
Returns a ‘Cyclop::Job` or `nil` if nothing to process
# File lib/cyclop.rb, line 102 def next(*args) opts = extract_opts! args Cyclop::Job.next({queues: args, locked_by: master_id}.merge opts) end
push(opts={})
click to toggle source
Queues a new job
Minimum usage: Cyclop.push queue: "refresh_cache" With `:job_params`: # with an `Array` Cyclop.push queue: "email", job_params: ["1", :welcome] # with a `Hash` Cyclop.push queue: "email", job_params: {user_id: "1", type: "welcome"} With `:delay`: # Will not perform the task before a delay of 60 seconds Cyclop.push queue: "email", delay: 60 With `:retries` and `:splay`: # Will mark the task as failed only after 3 retries Cyclop.push queue: "email", retries: 3 # Will mark the task as failed only after 2 retries # and 30 seconds between each retry Cyclop.push queue: "email", retries: 2, splay: 30
Parameters:
* (Hash) opts (defaults to: {}) - a customizable set of options. The minimum required is :queue.
Options Hash (opts):
* (Symbol, String) :queue - name of the queue (required). * (Array, Hash) :job_params (nil) - parameters to send to the `Cyclop::Job#perform` method. * (Integer) :delay (0) - time to wait in `seconds` before the task should be performed. * (Integer) :retries (0) - number of retries before the `Cyclop::Job` is marked as failed. * (Integer) :splay (60) - time to wait in `seconds` between retry. * (String) :host (Cyclop.host) - host under which the `Cyclop::Job` should be added.
Returns a ‘Cyclop::Job`
# File lib/cyclop.rb, line 84 def push(opts={}) opts["created_by"] = opts.delete :host Cyclop::Job.create opts end
Private Instance Methods
extract_opts!(args)
click to toggle source
# File lib/cyclop.rb, line 129 def extract_opts!(args) (args.pop if args.last.is_a?(Hash)) || {} end