Class: Wurk::Cron::LoopSet

Inherits:
Object
  • Object
show all
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

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.



414
415
416
# File 'lib/wurk/cron.rb', line 414

def initialize(config = nil)
  @config = config
end

Instance Method Details

#eachObject



418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/wurk/cron.rb', line 418

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



436
437
438
439
440
441
442
443
444
# File 'lib/wurk/cron.rb', line 436

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

#sizeObject



432
433
434
# File 'lib/wurk/cron.rb', line 432

def size
  redis { |c| c.call('SCARD', PERIODIC_KEY).to_i }
end