Class: Wurk::Cron::LoopSet
- Inherits:
-
Object
- Object
- Wurk::Cron::LoopSet
- Includes:
- Enumerable
- Defined in:
- lib/wurk/cron.rb
Overview
Enumerable view of every registered loop. Reads periodic SET +
loops:{lid} HASH on each iteration — cheap because the dashboard's
list view is the only hot caller.
Instance Method Summary collapse
- #each ⇒ Object
- #fetch(lid) ⇒ Object
-
#initialize(config = nil) ⇒ LoopSet
constructor
configscopes Redis to that config's per-fork pool — the leader poller runs inside a swarm child and must not reach for the parent-inherited global socket. - #size ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ LoopSet
config scopes Redis to that config's per-fork pool — the leader poller
runs inside a swarm child and must not reach for the parent-inherited
global socket. Dashboard/CLI callers pass nothing and get Wurk.redis.
447 448 449 |
# File 'lib/wurk/cron.rb', line 447 def initialize(config = nil) @config = config end |
Instance Method Details
#each ⇒ Object
451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/wurk/cron.rb', line 451 def each return enum_for(:each) unless block_given? redis do |c| lids = c.call('SMEMBERS', PERIODIC_KEY) lids.each do |lid| h = c.call('HGETALL', "#{LOOP_PREFIX}#{lid}") next if h.nil? || h.empty? yield Loop.from_redis(lid, h) end end end |
#fetch(lid) ⇒ Object
469 470 471 472 473 474 475 476 477 |
# File 'lib/wurk/cron.rb', line 469 def fetch(lid) h = redis { |c| c.call('HGETALL', "#{LOOP_PREFIX}#{lid}") } return nil if h.nil? || h.empty? h = h.each_slice(2).to_h if h.is_a?(Array) return nil if h.empty? Loop.from_redis(lid, h) end |
#size ⇒ Object
465 466 467 |
# File 'lib/wurk/cron.rb', line 465 def size redis { |c| c.call('SCARD', PERIODIC_KEY).to_i } end |