Module: Jobber
Instance Method Summary collapse
- #config ⇒ Object
- #deliver(job, *arguments) ⇒ Object
- #job_data(job, args, at: nil) ⇒ Object
- #ljobs(size = 1) ⇒ Object
- #queue_key ⇒ Object
- #redis ⇒ Object
- #redis_pool ⇒ Object
- #rjobs(size = 1) ⇒ Object
Instance Method Details
#config ⇒ Object
68 69 70 |
# File 'lib/rails_com/utils/jobber.rb', line 68 def config @config ||= Rails.application.config_for('jobber') end |
#deliver(job, *arguments) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rails_com/utils/jobber.rb', line 6 def deliver(job, *arguments) msg = job_data(job, arguments) r = redis_pool.with do |conn| conn.pipelined do conn.lpush(queue_key, JSON.dump(msg)) conn.lrange(queue_key, 0, 0) end end JSON.load(r[1].first) end |
#job_data(job, args, at: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_com/utils/jobber.rb', line 18 def job_data(job, args, at: nil) { class: 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper', wrapped: job, queue: config['queue'], args: [ { job_class: job, job_id: SecureRandom.uuid, queue_name: config['queue'], priority: nil, arguments: args, locale: 'en' } ], retry: true, jid: SecureRandom.hex(12), created_at: Time.now.to_f, enqueued_at: Time.now.to_f } end |
#ljobs(size = 1) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/rails_com/utils/jobber.rb', line 47 def ljobs(size = 1) result = redis_pool.with do |conn| conn.lrange(queue_key, 0, size - 1) end result.map do |r| JSON.load(r) end end |
#queue_key ⇒ Object
56 57 58 |
# File 'lib/rails_com/utils/jobber.rb', line 56 def queue_key @queue_key ||= "queue:#{config['queue']}" end |
#redis ⇒ Object
64 65 66 |
# File 'lib/rails_com/utils/jobber.rb', line 64 def redis Redis.new(url: config['url']) end |
#redis_pool ⇒ Object
60 61 62 |
# File 'lib/rails_com/utils/jobber.rb', line 60 def redis_pool @redis_pool ||= ConnectionPool.new(size: 5, timeout: 5) { Redis.new(url: config['url']) } end |
#rjobs(size = 1) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/rails_com/utils/jobber.rb', line 38 def rjobs(size = 1) result = redis_pool.with do |conn| conn.lrange(queue_key, -size, -1) end result.map do |r| JSON.load(r) end end |