wurk 1.11.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9594aab6027f299c217e81215d9d10d5764a5f5533b3e40cde2cd1feaae8a86
4
- data.tar.gz: 26161ff0d0ea58e60acbabd550e212ca354824f31434f0d085fabbc9401b8490
3
+ metadata.gz: 8153a2b51dcd55ed7857e54b5cd2d533ca0e37f7d443e93f5d2bc33e5be171c4
4
+ data.tar.gz: 85ee27f3ee4bb24004aa8d50372f0a555312e3a9607f8b1f644155d24722114e
5
5
  SHA512:
6
- metadata.gz: 3f2c0b2115f2c7132ab9104e7850f85cf34ac694d4d67b89f615cac765112582506197ae139753489de05f7e6217abb7770129aefbd3125e6dd2be17c04a50ac
7
- data.tar.gz: 0f08e99addbeeebefc503916d3a033aa88dd9ccc3ad1f557ce4aabfd43e7809b07392589e0137deff11b358304b435ed798766d89f3d3f205c3a105484a65875
6
+ metadata.gz: 4153f8cfbcd87743ec7b13a9433ffd2fa2238fbe7a4e5aeae3041d1f14fbea8c74a009287b418e934273938bed6ec619c1671bb411ae0de8c979532a0f7f4fca
7
+ data.tar.gz: ae57460f22da77be15b74a36a2b870630eeec2c694dab6e25e3e28bdfe4b48cf6264703e0167b6a47cf5d1258b2d96c168b57370a9172a6dbc34dde0ec2d53fe
@@ -473,7 +473,8 @@ module Wurk
473
473
  # Yields a Wurk::Cron::Manager so the host app can register periodic
474
474
  # jobs at boot. Manager state is shared per-process so multiple
475
475
  # `config.periodic` blocks accumulate (matches Sidekiq Ent §2.1). This is
476
- # the native replacement for the `sidekiq-cron` gem.
476
+ # the native replacement for the `sidekiq-cron` gem. Nothing reaches
477
+ # Redis until the server boots (#apply_periodic!).
477
478
  #
478
479
  # @example Register cron jobs at boot
479
480
  # Wurk.configure_server do |config|
@@ -488,11 +489,19 @@ module Wurk
488
489
  # Spec: docs/target/sidekiq-ent.md §2.
489
490
  def periodic
490
491
  require_relative 'cron'
491
- @periodic_manager ||= Wurk::Cron::Manager.new(self)
492
+ @periodic_manager ||= Wurk::Cron::Manager.new(self, deferred: true)
492
493
  yield @periodic_manager if block_given?
493
494
  @periodic_manager
494
495
  end
495
496
 
497
+ # Writes the `config.periodic` registrations to Redis. Launcher#boot calls
498
+ # it, so the loops are registered by a booting server, against the Redis
499
+ # settings the app ended up with.
500
+ def apply_periodic!
501
+ @periodic_manager&.apply!
502
+ nil
503
+ end
504
+
496
505
  # --- Historical metrics snapshotter (Ent §5) -------------------------
497
506
 
498
507
  HISTORY_DEFAULT_INTERVAL = 30
data/lib/wurk/cron.rb CHANGED
@@ -25,7 +25,8 @@ module Wurk
25
25
  # so a re-registration of the same loop is idempotent.
26
26
  # * `Cron::Manager` — registration DSL. `mgr.register(cron, klass, **opts)`
27
27
  # with `tz=` mass-setter. Writes to Redis (`periodic` SET + `loops:{lid}`
28
- # HASH) and prunes superseded loops for the classes it registers.
28
+ # HASH) and prunes superseded loops for the classes it registers; the
29
+ # `config.periodic` one defers both until the server boots.
29
30
  # * `Cron::LoopSet` — Enumerable view (`each`/`size`/`fetch(lid)`).
30
31
  # * `Cron::ConfigTester` — boot-time validator. Verifies cron syntax and
31
32
  # that every worker class constant resolves.
@@ -46,6 +47,10 @@ module Wurk
46
47
  DEFAULT_TICK_SECONDS = 60
47
48
  MISSED_TICK_THRESHOLD = 90
48
49
 
50
+ # Handed to the error handlers when a due loop names a class this process
51
+ # cannot load, so the occurrence was skipped.
52
+ class UnknownWorkerClass < Wurk::Error; end
53
+
49
54
  # 5-field crontab + `@aliases`. No seconds field, no DOW name aliases
50
55
  # (sidekiq-ent §2.2 uses numeric DOW only).
51
56
  class Parser
@@ -441,12 +446,17 @@ module Wurk
441
446
  attr_reader :loops
442
447
 
443
448
  # `prune: false` registers without superseding — ConfigTester uses it so
444
- # validating a config never deletes a live loop.
445
- def initialize(config = nil, prune: true)
449
+ # validating a config never deletes a live loop. `deferred: true` holds
450
+ # every write until #apply!: `config.periodic` runs while the initializers
451
+ # load, before the app has finished configuring Redis, and in processes
452
+ # that never boot a server (Ent registers on startup).
453
+ def initialize(config = nil, prune: true, deferred: false)
446
454
  @config = config
447
455
  @loops = []
448
456
  @tz = nil
449
457
  @prune = prune
458
+ @deferred = deferred
459
+ @authoritative = false
450
460
  @pruned_klasses = {}
451
461
  end
452
462
 
@@ -471,11 +481,22 @@ module Wurk
471
481
  normalized = opts.transform_keys(&:to_s)
472
482
  loop_obj = Loop.new(schedule: cron, klass: klass_name, options: normalized, tz: tz)
473
483
  @loops << loop_obj
474
- Cron.persist(loop_obj)
475
- prune_superseded(klass_name)
484
+ persist(loop_obj) unless @deferred
476
485
  loop_obj
477
486
  end
478
487
 
488
+ # Writes the registrations held back since `config.periodic` ran, then
489
+ # prunes as #register and #authoritative! would have. Launcher#boot calls
490
+ # it; once applied, later registrations are written as they come.
491
+ def apply!
492
+ return self unless @deferred
493
+
494
+ @deferred = false
495
+ @loops.each { |loop_obj| persist(loop_obj) }
496
+ prune_unregistered if @authoritative
497
+ self
498
+ end
499
+
479
500
  # Registers a sidekiq-cron shaped schedule: `{ name => { cron:, class:,
480
501
  # queue:, args:, retry:, tz:, status: } }`, or a list of those carrying
481
502
  # `name:`. Other keys (`description`, ...) are ignored. Raises ArgumentError
@@ -500,13 +521,23 @@ module Wurk
500
521
  def authoritative!
501
522
  return self unless @prune
502
523
 
503
- keep = @loops.map(&:lid)
504
- LoopSet.new(@config).each { |existing| Cron.unregister(existing.lid) unless keep.include?(existing.lid) }
524
+ @authoritative = true
525
+ prune_unregistered unless @deferred
505
526
  self
506
527
  end
507
528
 
508
529
  private
509
530
 
531
+ def persist(loop_obj)
532
+ Cron.persist(loop_obj)
533
+ prune_superseded(loop_obj.klass)
534
+ end
535
+
536
+ def prune_unregistered
537
+ keep = @loops.map(&:lid)
538
+ LoopSet.new(@config).each { |existing| Cron.unregister(existing.lid) unless keep.include?(existing.lid) }
539
+ end
540
+
510
541
  def register_entry(entry)
511
542
  cron = entry['cron'].to_s.strip
512
543
  klass = (entry['class'] || entry['klass']).to_s
@@ -647,6 +678,7 @@ module Wurk
647
678
  @mutex = ::Mutex.new
648
679
  @sleeper = ::ConditionVariable.new
649
680
  @on_leader = method(:wake_for_leadership)
681
+ @unknown_reported = ::Set.new
650
682
  end
651
683
 
652
684
  # The loop waits one interval before its first tick unless this process
@@ -723,9 +755,7 @@ module Wurk
723
755
  skip_missed(loop_obj, slot, now) unless firing == slot
724
756
  return if firing.nil?
725
757
 
726
- jid = enqueue_claimed!(loop_obj)
727
- record_history(loop_obj, jid, now)
728
- jid
758
+ fire_claimed(loop_obj, now)
729
759
  end
730
760
 
731
761
  # Fire one loop right now, bypassing both the leader gate and the
@@ -814,6 +844,32 @@ module Wurk
814
844
  nil
815
845
  end
816
846
 
847
+ def fire_claimed(loop_obj, now)
848
+ return skip_unknown_class(loop_obj) unless loop_obj.worker_class
849
+
850
+ jid = enqueue_claimed!(loop_obj)
851
+ record_history(loop_obj, jid, now)
852
+ jid
853
+ end
854
+
855
+ # Ent's tick is `klass.perform_async`, which needs the class. Pushing the
856
+ # bare name instead drops the worker's sidekiq_options, so a job that
857
+ # declares `retry: 0` failed with NameError under the default retries on
858
+ # every tick. The leader boots the app's code, so a class it cannot load
859
+ # is one that was deleted, renamed or rolled back; its loop stays in Redis
860
+ # until `Cron.unregister(lid)` or `authoritative!`. Logged on every
861
+ # occurrence, reported once per loop per process.
862
+ def skip_unknown_class(loop_obj)
863
+ message = "[cron] class #{loop_obj.klass} is not defined in this process lid=#{loop_obj.lid} — " \
864
+ 'occurrence skipped; Wurk::Cron.unregister(lid) retires the loop'
865
+ logger.warn(message)
866
+ return unless @unknown_reported.add?(loop_obj.lid)
867
+
868
+ handle_exception(UnknownWorkerClass.new(message),
869
+ { context: 'cron-poller', lid: loop_obj.lid, klass: loop_obj.klass })
870
+ nil
871
+ end
872
+
817
873
  # Compare-and-swap the fire marks: only the tick still looking at the
818
874
  # mark it read wins the slot. Manual `#fire` deliberately skips this —
819
875
  # an operator-requested run contends with no schedule slot.
@@ -99,7 +99,7 @@ module Wurk
99
99
  gate = @gates[keys[1]]
100
100
  next if gate&.blocked?(now)
101
101
 
102
- uow = gate ? claim(public_q, keys, gate, ack, now) : lmove(public_q, ack)
102
+ uow = gate ? claim(public_q, keys, gate, ack) : lmove(public_q, ack)
103
103
  ack = nil
104
104
  return uow if uow
105
105
  end
@@ -124,7 +124,7 @@ module Wurk
124
124
  # is deferred: an ACK handed back by a failed flush must not be able to
125
125
  # take the hold of whatever this thread is running by then. See
126
126
  # QueueSlot.claim_token.
127
- def claim(public_q, keys, gate, ack, now)
127
+ def claim(public_q, keys, gate, ack)
128
128
  priv, name = keys
129
129
  token = QueueSlot.claim_token
130
130
  script_keys = [gate.slot_key, public_q, priv]
@@ -137,7 +137,12 @@ module Wurk
137
137
  # faster than a job finishes somewhere in the cluster, so re-asking on
138
138
  # every pass is how a full queue turns into a spin. An empty queue is
139
139
  # remembered by nobody, exactly as on the uncapped path.
140
- gate.block!(now) if status == AT_CAPACITY
140
+ #
141
+ # Stamped with the time the refusal ARRIVED, not the time the question
142
+ # was sent: a slow Redis would otherwise eat the backoff window and
143
+ # the gate would already be expired when the refusal lands — which is
144
+ # the spin this remembers it to avoid.
145
+ gate.block!(::Process.clock_gettime(::Process::CLOCK_MONOTONIC)) if status == AT_CAPACITY
141
146
  nil
142
147
  rescue StandardError
143
148
  # The window #lmove guards: the ACK left its slot but never reached
data/lib/wurk/launcher.rb CHANGED
@@ -99,10 +99,12 @@ module Wurk
99
99
  # 4. start the reaper and the boot-time reclaim sweep — kill-9 recovery,
100
100
  # not decoration: a SIGKILLed sibling's in-flight jobs wait on this,
101
101
  # so it stays ahead of the periodic loops.
102
- # 5. start the periodic loops. None of them ticks at zero — TimerLoop#run
103
- # waits an interval before its first yield, Scheduled::Poller waits
104
- # INITIAL_WAIT, and Leader waits DEFAULT_INITIAL_WAIT — so starting
105
- # them last costs a few thread spawns and nothing else. Both leader-
102
+ # 5. write the `config.periodic` registrations (Ent registers loops on
103
+ # startup), then start the periodic loops. None of them ticks at
104
+ # zero — TimerLoop#run waits an interval before its first yield,
105
+ # Scheduled::Poller waits INITIAL_WAIT, and Leader waits
106
+ # DEFAULT_INITIAL_WAIT — so starting them last costs a few thread
107
+ # spawns and nothing else. Both leader-
106
108
  # gated pollers are also safe to start before leadership settles: a
107
109
  # non-leader tick just returns early.
108
110
  # 6. start the health probe server LAST so the listener doesn't
@@ -240,6 +242,7 @@ module Wurk
240
242
  # Run on a background thread so /ready probe isn't delayed by a large
241
243
  # orphan sweep (the reaper's reclaim is atomic, but can scan many entries).
242
244
  @boot_reclaim_thread = safe_thread('boot-reclaim', &method(:boot_reclaim))
245
+ @config.apply_periodic!
243
246
  start_periodic_components
244
247
  end
245
248
  @health_server&.start
data/lib/wurk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wurk
4
- VERSION = '1.11.0'
4
+ VERSION = '1.11.1'
5
5
  end
@@ -0,0 +1,16 @@
1
+ <% extras = job.item.reject { |key, _| RETRY_JOB_KEYS.include?(key) } %>
2
+ <header><h2><%= t('Job') %></h2></header>
3
+ <div class="table_container">
4
+ <table class="table">
5
+ <tbody>
6
+ <tr><th><%= t('Queue') %></th><td><%= h(job.queue) %></td></tr>
7
+ <tr><th><%= t('Job') %></th><td><code><%= h(job.display_class) %></code></td></tr>
8
+ <tr><th><%= t('Arguments') %></th><td><code class="code-wrap"><%= display_args(job.display_args) %></code></td></tr>
9
+ <tr><th><%= t('JID') %></th><td><code><%= h(job.jid) %></code></td></tr>
10
+ <% if job.created_at %><tr><th><%= t('CreatedAt') %></th><td><%= relative_time(job.created_at) %></td></tr><% end %>
11
+ <% if job.enqueued_at %><tr><th><%= t('Enqueued') %></th><td><%= relative_time(job.enqueued_at) %></td></tr><% end %>
12
+ <% if job['retry_count'] %><tr><th><%= t('RetryCount') %></th><td><%= h(job['retry_count']) %></td></tr><% end %>
13
+ <% extras.each do |key, value| %><tr><th><%= h(key) %></th><td><code><%= h(truncate(value.inspect)) %></code></td></tr><% end %>
14
+ </tbody>
15
+ </table>
16
+ </div>
@@ -0,0 +1,11 @@
1
+ <% last_page = @count.to_i.positive? ? (@total_size.to_f / @count).ceil : 1 %>
2
+ <% current = @current_page.to_i %>
3
+ <% if last_page > 1 %>
4
+ <ul class="pagination">
5
+ <li class="<%= 'disabled' if current <= 1 %>"><a href="<%= h(url) %>?<%= h(qparams(page: 1)) %>">&laquo;</a></li>
6
+ <% if current > 1 %><li><a href="<%= h(url) %>?<%= h(qparams(page: current - 1)) %>"><%= current - 1 %></a></li><% end %>
7
+ <li class="disabled"><a href="<%= h(url) %>?<%= h(qparams(page: current)) %>"><%= current %></a></li>
8
+ <% if current < last_page %><li><a href="<%= h(url) %>?<%= h(qparams(page: current + 1)) %>"><%= current + 1 %></a></li><% end %>
9
+ <li class="<%= 'disabled' if current >= last_page %>"><a href="<%= h(url) %>?<%= h(qparams(page: last_page)) %>">&raquo;</a></li>
10
+ </ul>
11
+ <% end %>
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "1.11.0",
3
- "timestamp": "2026-11-03T06:58:20.943Z"
2
+ "version": "1.11.1",
3
+ "timestamp": "2026-11-06T19:41:47.878Z"
4
4
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wurk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - developerz.ai
@@ -437,6 +437,8 @@ files:
437
437
  - lib/wurk/web/pool_scope.rb
438
438
  - lib/wurk/web/rack_app.rb
439
439
  - lib/wurk/web/search.rb
440
+ - lib/wurk/web/views/_job_info.erb
441
+ - lib/wurk/web/views/_paging.erb
440
442
  - lib/wurk/work_set.rb
441
443
  - lib/wurk/worker.rb
442
444
  - lib/wurk/worker/setter.rb