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
- #empty? ⇒ Boolean
-
#initialize(redis:, build_id:) ⇒ Base
constructor
A new instance of Base.
- #progress ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #wait_for_master(timeout: 10) ⇒ Object
- #workers_count ⇒ Object
Constructor Details
#initialize(redis:, build_id:) ⇒ Base
Returns a new instance of Base.
5 6 7 8 |
# File 'lib/ci/queue/redis/base.rb', line 5 def initialize(redis:, build_id:) @redis = redis @build_id = build_id end |
Instance Method Details
#empty? ⇒ Boolean
10 11 12 |
# File 'lib/ci/queue/redis/base.rb', line 10 def empty? size == 0 end |
#progress ⇒ Object
28 29 30 |
# File 'lib/ci/queue/redis/base.rb', line 28 def progress total - size end |
#size ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ci/queue/redis/base.rb', line 14 def size redis.multi do redis.llen(key('queue')) redis.zcard(key('running')) end.inject(:+) end |
#to_a ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ci/queue/redis/base.rb', line 21 def to_a redis.multi do redis.lrange(key('queue'), 0, -1) redis.zrange(key('running'), 0, -1) end.flatten.reverse end |
#wait_for_master(timeout: 10) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ci/queue/redis/base.rb', line 32 def wait_for_master(timeout: 10) return true if master? (timeout * 10 + 1).to_i.times do case master_status when 'ready', 'finished' 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 |