Class: Wurk::Scheduled::ReliableEnq

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

Overview

Reliable variant of Enq (Pro §4). The default Enq pops then pushes —a crash between the ZPOPBYSCORE and the client push loses the job. ReliableEnq instead promotes every due job from each set onto its target queue in a single atomic Lua (ZRANGEBYSCORE → LPUSH queue:<q> → ZREM), so there is no window where a job exists in neither place. Swapped in by ‘config.reliable_scheduler!` via the `scheduled_enq` seam.

Spec: docs/target/sidekiq-pro.md §4.

Constant Summary

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) ⇒ ReliableEnq

Returns a new instance of ReliableEnq.



81
82
83
84
# File 'lib/wurk/scheduled.rb', line 81

def initialize(container)
  @config = container
  @done = false
end

Instance Method Details

#enqueue_jobs(sorted_sets = SETS) ⇒ Object



86
87
88
89
90
# File 'lib/wurk/scheduled.rb', line 86

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

#terminateObject



92
93
94
# File 'lib/wurk/scheduled.rb', line 92

def terminate
  @done = true
end