Class: Wurk::Scheduled::Enq

Inherits:
Object
  • Object
show all
Includes:
Component
Defined in:
lib/wurk/scheduled.rb

Overview

Drains both SETS each call. Iterates per-set inside a single pooled checkout so the EVALSHA + LPUSH loop avoids re-checkout per job.

Constant Summary collapse

LUA_ZPOPBYSCORE =
Wurk::Lua::ZPOPBYSCORE

Constants included from Component

Component::DEFAULT_THREAD_PRIORITY, Component::PROCESS_NONCE

Instance Attribute Summary

Attributes included from Component

#config

Instance Method Summary collapse

Methods included from Component

#default_tag, #fire_event, #handle_exception, #hostname, #identity, #leader?, #logger, #mono_ms, #process_nonce, #real_ms, #redis, #safe_thread, #tid, #watchdog

Constructor Details

#initialize(container) ⇒ Enq

Returns a new instance of Enq.



32
33
34
35
36
# File 'lib/wurk/scheduled.rb', line 32

def initialize(container)
  @config = container
  @done = false
  @client = Client.new(config: container)
end

Instance Method Details

#enqueue_jobs(sorted_sets = SETS) ⇒ Object

Pops every due job from each sorted set and re-pushes through the client. ‘now` is captured once per set so a slow loop on one ZSET can’t keep grabbing newly-scheduled jobs from a moving window.



41
42
43
44
45
# File 'lib/wurk/scheduled.rb', line 41

def enqueue_jobs(sorted_sets = SETS)
  @config.redis do |conn|
    sorted_sets.each { |sset| drain_set(conn, sset) }
  end
end

#terminateObject



47
48
49
# File 'lib/wurk/scheduled.rb', line 47

def terminate
  @done = true
end