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.



372
373
374
# File 'lib/wurk/cron.rb', line 372

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

Instance Method Details

#eachObject



376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/wurk/cron.rb', line 376

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



394
395
396
397
398
399
400
401
402
# File 'lib/wurk/cron.rb', line 394

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



390
391
392
# File 'lib/wurk/cron.rb', line 390

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