wurk 1.18.0 → 1.19.0

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: 0e76dc31e4cdd0cb170fb6d3882e01ce20596a4092938d87401eef04f26f30a0
4
- data.tar.gz: 480f9e50d3a4360f23825b0cb6479e7ac4c3dda891a52c253731adf32ebe1ce6
3
+ metadata.gz: baff6a3f75bca45d6dbcbed8c3363b306ef0f37f8c48f9de0fac68f320ab9a79
4
+ data.tar.gz: 3e1725ade18090f1d9eca95d0d3b016db9a15747f63bed75b4ef6cc95555982e
5
5
  SHA512:
6
- metadata.gz: f281b9e976f9c75961588a310f8544eed21e47bb835b3f31fec6155cd6dc4a670d04a15acc8bfbbaeaa0e55428c46aaf9375475c02891137ac090b54b27a5577
7
- data.tar.gz: 200d2fa2e32212ba98e8f4c190f08791edda35a3308fe597830e8eea2c8863d3a60f29508799897d73e758891d1b6f20b5b096bd8dc9a8ac3b84c0ff71c72dc5
6
+ metadata.gz: 78be5c5f73decd87bda36782bde1ab6d3698b6fc05ad659d6b167c2fba7b7e63cb3250dc3c3ed07016addf03376bceecf6ffb67072ac6df0fbd6b88d975d1824
7
+ data.tar.gz: 83e105bb40f2d95b89564cae52cd7fc85347bd6f131f822d91eac80b74d4ff45ee3c425e4a89fc87c8144717f0020b9a4de56584bfc1f03a76b72be074ae979e
data/README.md CHANGED
@@ -308,7 +308,7 @@ Wurk is MIT and stays that way. If what you need is a commercial support contrac
308
308
 
309
309
  `bundle install && restart`. The worker command stays as it was: Wurk ships `sidekiq` and `sidekiqswarm` executables, so `bundle exec sidekiq -C config/sidekiq.yml` in a Procfile or manifest keeps working. Wurk reads and writes the same Redis schema, so there is no data migration: Wurk picks up the queues, schedules, retries, batches and periodic loops Sidekiq left behind. Running Sidekiq and Wurk workers against one Redis *at the same time* is tested for stock Sidekiq 8 only, which may roll from one to the other under the conditions the guide lists; for a Sidekiq 7.x, Pro or Enterprise app a live production move is a **drain cutover** (stop Sidekiq's workers, confirm nothing is in flight, start Wurk), with a matching rollback. The [production cutover](https://github.com/developerz-ai/wurk/blob/main/docs/migrate-from-sidekiq.md#9-production-cutover) section has every step and command. The upstream suites of sidekiq-cron, sidekiq-unique-jobs, sidekiq-failures and sentry-sidekiq run against Wurk in the [`ecosystem` CI job](https://github.com/developerz-ai/wurk/blob/main/.github/workflows/ecosystem.yml) (see [`test/ecosystem/`](https://github.com/developerz-ai/wurk/tree/main/test/ecosystem)). sidekiq-scheduler, sidekiq-status and sidekiq-throttled are target additions tracked in [docs/idea/14-ecosystem-compat.md](https://github.com/developerz-ai/wurk/blob/main/docs/idea/14-ecosystem-compat.md).
310
310
 
311
- **Keeping a `sidekiq-*` add-on gem?** Those gems declare `add_dependency "sidekiq"`, which would reinstall real Sidekiq next to Wurk. Satisfy it with Wurk's git-only [`sidekiq` shim gem](https://github.com/developerz-ai/wurk/tree/main/ecosystem/sidekiq-shim) instead, pinned to the tag of the Wurk release you run: `gem "sidekiq", github: "developerz-ai/wurk", tag: "v1.18.0", glob: "ecosystem/sidekiq-shim/*.gemspec"`. Only sidekiq-cron, sidekiq-unique-jobs, sidekiq-failures and sentry-sidekiq are exercised that way, by the `ecosystem` workflow; treat the others as untested.
311
+ **Keeping a `sidekiq-*` add-on gem?** Those gems declare `add_dependency "sidekiq"`, which would reinstall real Sidekiq next to Wurk. Satisfy it with Wurk's git-only [`sidekiq` shim gem](https://github.com/developerz-ai/wurk/tree/main/ecosystem/sidekiq-shim) instead, pinned to the tag of the Wurk release you run: `gem "sidekiq", github: "developerz-ai/wurk", tag: "v1.19.0", glob: "ecosystem/sidekiq-shim/*.gemspec"`. Only sidekiq-cron, sidekiq-unique-jobs, sidekiq-failures and sentry-sidekiq are exercised that way, by the `ecosystem` workflow; treat the others as untested.
312
312
 
313
313
  Full walkthrough — config side-by-side, the Redis key/`sidekiq_options` mapping, known incompatibilities, moving sidekiq-cron schedules over (`rake wurk:import:cron`), and the production cutover and rollback playbook: **[docs/migrate-from-sidekiq.md](https://github.com/developerz-ai/wurk/blob/main/docs/migrate-from-sidekiq.md)**. On the night, keep the **[incident runbook](https://github.com/developerz-ai/wurk/blob/main/docs/runbook.md)** open.
314
314
 
@@ -0,0 +1,25 @@
1
+ -- Wurk only: sidekiq-unique-jobs 8.x has no refresh. Pushes out the expiry of a
2
+ -- lock this jid still holds, re-applying from now what lock.lua and
3
+ -- queue_and_lock.lua set when the lock was taken. Takes nothing: a jid that is
4
+ -- not in LOCKED gets 0 and no key is written. Every key is in KEYS.
5
+ -- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
6
+ -- ARGV = [jid, pttl, now]
7
+ -- Returns 1 when this jid holds the lock, 0 otherwise.
8
+ local digest, locked, info, expiring = KEYS[1], KEYS[4], KEYS[5], KEYS[8]
9
+ local job_id, pttl, now = ARGV[1], tonumber(ARGV[2]), tonumber(ARGV[3])
10
+
11
+ if redis.call("HEXISTS", locked, job_id) == 0 then
12
+ return 0
13
+ end
14
+
15
+ if pttl > 0 then
16
+ redis.call("PEXPIRE", digest, pttl)
17
+ redis.call("PEXPIRE", locked, pttl)
18
+ redis.call("PEXPIRE", info, pttl)
19
+ -- An until_expired lock is also indexed by expiry, and the reaper deletes it
20
+ -- once that score passes. Scored as lock.lua scores it (seconds plus
21
+ -- milliseconds, the gem's arithmetic); XX leaves every other digest out.
22
+ redis.call("ZADD", expiring, "XX", now + pttl, digest)
23
+ end
24
+
25
+ return 1
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wurk
4
+ module UniqueJobs
5
+ # `UniqueJobs.refresh_lock!`: pushes out the TTL of the lock a running job
6
+ # still holds, so a `perform` that can outlast any sane `lock_ttl` keeps its
7
+ # lock by renewing it instead of by a TTL long enough to cover the slowest
8
+ # run (which a crashed run then holds for just as long). Wurk only: the gem
9
+ # sets a lock's TTL once, when the lock is taken.
10
+ #
11
+ # One script (`unique_jobs_refresh.lua`) checks that the jid is still in the
12
+ # lock's LOCKED hash and only then re-applies the expiry; it never takes a
13
+ # lock, so a refresh that comes too late returns false and the caller
14
+ # decides what a lost lock means for its run.
15
+ class LockRefresh
16
+ # The types whose lock during `perform` is the runtime one, `<digest>:RUN`.
17
+ # until_and_while_executing gave up its push lock when `perform` started.
18
+ RUNTIME_LOCKS = [Lock::WhileExecuting, Lock::UntilAndWhileExecuting].freeze
19
+
20
+ # The payload of every unique job running in this process, by jid, so the
21
+ # job (or a thread it started) can name its lock by jid alone. Filled by
22
+ # the server middleware around `perform`.
23
+ module Running
24
+ @items = {}
25
+ @mutex = ::Mutex.new
26
+
27
+ class << self
28
+ def track(item)
29
+ jid = item[JID]
30
+ @mutex.synchronize { @items[jid] = item }
31
+ yield
32
+ ensure
33
+ @mutex.synchronize { @items.delete(jid) }
34
+ end
35
+
36
+ def [](jid) = @mutex.synchronize { @items[jid] }
37
+ end
38
+ end
39
+
40
+ def initialize(job, ttl: nil)
41
+ @item = item_for(job)
42
+ @pttl = pttl_for(ttl)
43
+ end
44
+
45
+ def call
46
+ UniqueJobs.redis do |conn|
47
+ Script.call(:unique_jobs_refresh, conn, keys: key.to_a, argv: [@item[JID], @pttl, UniqueJobs.now_f])
48
+ end == 1
49
+ end
50
+
51
+ private
52
+
53
+ def item_for(job)
54
+ item = case job
55
+ when ::Hash then job
56
+ when ::String then running(job)
57
+ else
58
+ raise ::ArgumentError, "expected a job payload, a jid or a job instance, got #{job.inspect}" \
59
+ unless job.class.respond_to?(:get_sidekiq_options)
60
+
61
+ running(job.jid)
62
+ end
63
+ [JID, LOCK, LOCK_DIGEST].each do |field|
64
+ raise ::ArgumentError, "not a unique job payload: no `#{field}` in #{item.inspect}" unless item[field]
65
+ end
66
+ item
67
+ end
68
+
69
+ def running(jid)
70
+ Running[jid] || raise(::ArgumentError,
71
+ "no job #{jid.inspect} is running under a Wurk::UniqueJobs lock in this process; " \
72
+ 'refresh_lock! by jid works only inside its perform (or a thread it started)')
73
+ end
74
+
75
+ # Seconds, from the caller or else the TTL the lock was taken with: the
76
+ # `lock_ttl` the payload carries. 0 means the lock never expires, so a
77
+ # refresh only answers whether it is still held.
78
+ def pttl_for(ttl)
79
+ return LockConfig.new(@item).pttl if ttl.nil?
80
+ raise ::ArgumentError, "ttl must be a positive number of seconds, got #{ttl.inspect}" \
81
+ unless ttl.is_a?(::Numeric) && (ttl * 1_000).to_i.positive?
82
+
83
+ (ttl * 1_000).to_i
84
+ end
85
+
86
+ def key
87
+ digest = @item[LOCK_DIGEST]
88
+ runtime = RUNTIME_LOCKS.any? { |klass| lock_class <= klass }
89
+ Key.new(runtime && !digest.end_with?(RUN_SUFFIX) ? "#{digest}#{RUN_SUFFIX}" : digest)
90
+ end
91
+
92
+ def lock_class
93
+ type = @item[LOCK].to_sym
94
+ UniqueJobs.locks.fetch(type) { raise UnknownLock, "No implementation for `lock: :#{type}`" }
95
+ end
96
+ end
97
+ end
98
+ end
@@ -82,7 +82,7 @@ module Wurk
82
82
  def call(worker, item, _queue, &)
83
83
  return yield unless lockable?(worker, item)
84
84
 
85
- with_context(:server) { lock_instance.execute(&) }
85
+ with_context(:server) { LockRefresh::Running.track(item) { lock_instance.execute(&) } }
86
86
  end
87
87
  end
88
88
  end
@@ -8,6 +8,7 @@ require_relative 'unique_jobs/job'
8
8
  require_relative 'unique_jobs/locksmith'
9
9
  require_relative 'unique_jobs/on_conflict'
10
10
  require_relative 'unique_jobs/lock'
11
+ require_relative 'unique_jobs/lock_refresh'
11
12
  require_relative 'unique_jobs/digests'
12
13
  require_relative 'unique_jobs/middleware'
13
14
  require_relative 'unique_jobs/orphans'
@@ -26,6 +27,7 @@ module Wurk
26
27
  # - A waiting lock blocks on its own connection, not a concurrent-ruby future.
27
28
  # - The reaper reads each job once per run, not once per digest, and counts
28
29
  # jobs in wurk's private lists as live (see Orphans::Reaper).
30
+ # - `refresh_lock!` renews a running job's lock (LockRefresh); the gem has none.
29
31
  # - No changelog debug logging (`debug_lua`), CLI, upgrade from v6 locks or
30
32
  # version keys: there is nothing to upgrade from.
31
33
  module UniqueJobs
@@ -80,6 +82,13 @@ module Wurk
80
82
  config.enabled = was if block_given?
81
83
  end
82
84
 
85
+ # Pushes out the TTL of the lock `job` holds while it runs: `job` is the
86
+ # running job instance (`self` in `perform`), its jid, or its payload.
87
+ # True when this jid still held the lock (now good for `ttl` seconds, by
88
+ # default the `lock_ttl` it was taken with); false when it no longer did,
89
+ # and then nothing is written. See LockRefresh.
90
+ def refresh_lock!(job, ttl: nil) = LockRefresh.new(job, ttl: ttl).call
91
+
83
92
  def reflections = @reflections ||= Reflections.new
84
93
  def reflect = yield(reflections)
85
94
  def redis(&) = Wurk.redis(&)
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.18.0'
4
+ VERSION = '1.19.0'
5
5
  end
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "1.18.0",
3
- "timestamp": "2026-11-23T05:16:18.120Z"
2
+ "version": "1.19.0",
3
+ "timestamp": "2026-11-23T15:33:33.692Z"
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.18.0
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - developerz.ai
@@ -364,6 +364,7 @@ files:
364
364
  - lib/wurk/lua/unique_jobs_lock.lua
365
365
  - lib/wurk/lua/unique_jobs_queue.lua
366
366
  - lib/wurk/lua/unique_jobs_queue_and_lock.lua
367
+ - lib/wurk/lua/unique_jobs_refresh.lua
367
368
  - lib/wurk/lua/unique_jobs_unlock.lua
368
369
  - lib/wurk/manager.rb
369
370
  - lib/wurk/metrics.rb
@@ -475,6 +476,7 @@ files:
475
476
  - lib/wurk/unique_jobs/errors.rb
476
477
  - lib/wurk/unique_jobs/job.rb
477
478
  - lib/wurk/unique_jobs/lock.rb
479
+ - lib/wurk/unique_jobs/lock_refresh.rb
478
480
  - lib/wurk/unique_jobs/locksmith.rb
479
481
  - lib/wurk/unique_jobs/middleware.rb
480
482
  - lib/wurk/unique_jobs/on_conflict.rb