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

Instance Attribute Summary collapse

Instance Method Summary collapse

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 Attribute Details

#configObject (readonly) Originally defined in module Component

Returns the value of attribute config.

Instance Method Details

#default_tag(dir = Dir.pwd) ⇒ Object Originally defined in module Component

#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

#fire_event(event, oneshot: true, reverse: false, reraise: false) ⇒ Object Originally defined in module Component

Invokes lifecycle hooks for event. Hooks run in registration order (or LIFO when reverse: true, used for teardown). A raise in one hook is reported via handle_exception and does NOT stop the next hook unless reraise: true (used in tests / fail-fast boot). oneshot: true clears the bucket after dispatch so the event can't fire twice.

#handle_exception(ex, ctx = {}) ⇒ Object Originally defined in module Component

#hostnameObject Originally defined in module Component

#identityObject Originally defined in module Component

#leader?Boolean Originally defined in module Component

True iff this process currently holds the cluster dear-leader lock. Per spec, the check is performed at call time (Wurk does not cache); callers must not poll faster than the 60s follower cadence. Returns false unconditionally when WURK_LEADER=false (or SIDEKIQ_LEADER=false) is set on the process (opt-out hot-standby). Any Redis error is swallowed → false, so a transient partition can't propagate as an exception into user code.

Spec: docs/target/sidekiq-ent.md §6.1.

Returns:

  • (Boolean)

#loggerObject Originally defined in module Component

--- delegated to config -------------------------------------------

#mono_msObject Originally defined in module Component

#process_nonceObject Originally defined in module Component

#real_msObject Originally defined in module Component

--- clocks ---------------------------------------------------------

#redisObject Originally defined in module Component

#safe_thread(name, priority: nil, &block) ⇒ Object Originally defined in module Component

Spawns a named thread that runs block under watchdog(name). The parent must retain the returned Thread; otherwise GC may not, but report_on_exception is disabled so we don't double-log on death.

#terminateObject



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

def terminate
  @done = true
end

#tidObject Originally defined in module Component

--- identity -------------------------------------------------------

#watchdog(last_words) ⇒ Object Originally defined in module Component

Wraps a block at a thread boundary: any unhandled exception is reported via handle_exception (so it lands in error_handlers / the log) and then re-raised. last_words is the component label included in the context.