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
Loops are read up front and yielded with no connection held, so the caller's own Redis work (the poller's claim + push) never nests a second checkout.
- #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.
606 607 608 |
# File 'lib/wurk/cron.rb', line 606 def initialize(config = nil) @config = config end |
Instance Method Details
#each ⇒ Object
Loops are read up front and yielded with no connection held, so the caller's own Redis work (the poller's claim + push) never nests a second checkout. A loop whose stored hash no longer parses is skipped with a warning: one corrupt record must not hide every loop after it.
614 615 616 617 618 619 620 621 |
# File 'lib/wurk/cron.rb', line 614 def each return enum_for(:each) unless block_given? read_rows.each do |lid, h| loop_obj = parse(lid, h) yield loop_obj if loop_obj end end |
#fetch(lid) ⇒ Object
627 628 629 630 631 632 633 634 635 |
# File 'lib/wurk/cron.rb', line 627 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
623 624 625 |
# File 'lib/wurk/cron.rb', line 623 def size redis { |c| c.call('SCARD', PERIODIC_KEY).to_i } end |