Class: CI::Queue::Redis::Base
- Inherits:
-
Object
- Object
- CI::Queue::Redis::Base
- Defined in:
- lib/ci/queue/redis/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #exhausted? ⇒ Boolean
-
#initialize(redis_url, config) ⇒ Base
constructor
A new instance of Base.
- #progress ⇒ Object
- #queue_initialized? ⇒ Boolean
- #size ⇒ Object
- #to_a ⇒ Object
- #wait_for_master(timeout: 10) ⇒ Object
- #workers_count ⇒ Object
Constructor Details
#initialize(redis_url, config) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 |
# File 'lib/ci/queue/redis/base.rb', line 5 def initialize(redis_url, config) @redis_url = redis_url @redis = ::Redis.new(url: redis_url) @config = config end |
Instance Method Details
#exhausted? ⇒ Boolean
11 12 13 |
# File 'lib/ci/queue/redis/base.rb', line 11 def exhausted? queue_initialized? && size == 0 end |
#progress ⇒ Object
29 30 31 |
# File 'lib/ci/queue/redis/base.rb', line 29 def progress total - size end |
#queue_initialized? ⇒ Boolean
49 50 51 52 53 54 |
# File 'lib/ci/queue/redis/base.rb', line 49 def queue_initialized? @queue_initialized ||= begin status = master_status status == 'ready' || status == 'finished' end end |
#size ⇒ Object
15 16 17 18 19 20 |
# File 'lib/ci/queue/redis/base.rb', line 15 def size redis.multi do redis.llen(key('queue')) redis.zcard(key('running')) end.inject(:+) end |
#to_a ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ci/queue/redis/base.rb', line 22 def to_a redis.multi do redis.lrange(key('queue'), 0, -1) redis.zrange(key('running'), 0, -1) end.flatten.reverse.map { |k| index.fetch(k) } end |
#wait_for_master(timeout: 10) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ci/queue/redis/base.rb', line 33 def wait_for_master(timeout: 10) return true if master? (timeout * 10 + 1).to_i.times do if queue_initialized? return true else sleep 0.1 end end raise LostMaster, "The master worker is still `#{master_status}` after 10 seconds waiting." end |
#workers_count ⇒ Object
45 46 47 |
# File 'lib/ci/queue/redis/base.rb', line 45 def workers_count redis.scard(key('workers')) end |