Class: Jiggler::Job::Enqueuer
- Inherits:
-
Object
- Object
- Jiggler::Job::Enqueuer
- Defined in:
- lib/jiggler/job.rb
Instance Method Summary collapse
- #config ⇒ Object
- #enqueue(*args) ⇒ Object
- #enqueue_bulk(args_arr) ⇒ Object
- #enqueue_in(seconds, *args) ⇒ Object
-
#initialize(klass, options = {}) ⇒ Enqueuer
constructor
A new instance of Enqueuer.
- #job_args(raw_args) ⇒ Object
- #job_options ⇒ Object
- #list_name ⇒ Object
- #with_options(options) ⇒ Object
Constructor Details
#initialize(klass, options = {}) ⇒ Enqueuer
Returns a new instance of Enqueuer.
43 44 45 46 |
# File 'lib/jiggler/job.rb', line 43 def initialize(klass, = {}) @options = @klass = klass end |
Instance Method Details
#config ⇒ Object
95 96 97 |
# File 'lib/jiggler/job.rb', line 95 def config @config ||= Jiggler.config end |
#enqueue(*args) ⇒ Object
53 54 55 56 57 |
# File 'lib/jiggler/job.rb', line 53 def enqueue(*args) Jiggler.config.client_redis_pool.acquire do |conn| conn.call('LPUSH', list_name, job_args(args)) end end |
#enqueue_bulk(args_arr) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/jiggler/job.rb', line 59 def enqueue_bulk(args_arr) Jiggler.config.client_redis_pool.acquire do |conn| conn.pipelined do |pipeline| args_arr.each do |args| pipeline.call('LPUSH', list_name, job_args(args)) end end end end |
#enqueue_in(seconds, *args) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jiggler/job.rb', line 69 def enqueue_in(seconds, *args) = Time.now.to_f + seconds Jiggler.config.client_redis_pool.acquire do |conn| conn.call( 'ZADD', config.scheduled_set, , job_args(args) ) end end |
#job_args(raw_args) ⇒ Object
85 86 87 |
# File 'lib/jiggler/job.rb', line 85 def job_args(raw_args) Oj.dump({ name: @klass.name, args: raw_args, ** }, mode: :compat) end |
#job_options ⇒ Object
89 90 91 92 93 |
# File 'lib/jiggler/job.rb', line 89 def retries = @options.fetch(:retries, @klass.retries) jid = @options.fetch(:jid, SecureRandom.hex(8)) { retries: retries, jid: jid } end |
#list_name ⇒ Object
81 82 83 |
# File 'lib/jiggler/job.rb', line 81 def list_name "#{config.queue_prefix}#{@options.fetch(:queue, @klass.queue)}" end |
#with_options(options) ⇒ Object
48 49 50 51 |
# File 'lib/jiggler/job.rb', line 48 def () @options.merge() self end |