wurk 1.17.1 → 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.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/sidekiq/cron/web.rb +10 -0
  4. data/lib/sidekiq/cron.rb +10 -0
  5. data/lib/sidekiq-cron.rb +11 -0
  6. data/lib/wurk/boot_checks.rb +8 -6
  7. data/lib/wurk/compat.rb +19 -15
  8. data/lib/wurk/finished_job_cleanup.rb +3 -2
  9. data/lib/wurk/launcher.rb +15 -4
  10. data/lib/wurk/lua/unique_jobs_delete.lua +5 -0
  11. data/lib/wurk/lua/unique_jobs_delete_by_digest.lua +6 -0
  12. data/lib/wurk/lua/unique_jobs_delete_job_by_digest.lua +42 -0
  13. data/lib/wurk/lua/unique_jobs_lock.lua +54 -0
  14. data/lib/wurk/lua/unique_jobs_queue.lua +43 -0
  15. data/lib/wurk/lua/unique_jobs_queue_and_lock.lua +67 -0
  16. data/lib/wurk/lua/unique_jobs_refresh.lua +25 -0
  17. data/lib/wurk/lua/unique_jobs_unlock.lua +61 -0
  18. data/lib/wurk/preflight/checks.rb +6 -5
  19. data/lib/wurk/rspec.rb +246 -0
  20. data/lib/wurk/sidekiq_cron/arguments.rb +69 -0
  21. data/lib/wurk/sidekiq_cron/configuration.rb +43 -0
  22. data/lib/wurk/sidekiq_cron/job/enqueue.rb +142 -0
  23. data/lib/wurk/sidekiq_cron/job/store.rb +130 -0
  24. data/lib/wurk/sidekiq_cron/job.rb +292 -0
  25. data/lib/wurk/sidekiq_cron/namespace.rb +52 -0
  26. data/lib/wurk/sidekiq_cron/poller.rb +71 -0
  27. data/lib/wurk/sidekiq_cron/schedule.rb +114 -0
  28. data/lib/wurk/sidekiq_cron/schedule_loader.rb +50 -0
  29. data/lib/wurk/sidekiq_cron/web_rows.rb +55 -0
  30. data/lib/wurk/sidekiq_cron.rb +52 -0
  31. data/lib/wurk/unique_jobs/api_extension.rb +84 -0
  32. data/lib/wurk/unique_jobs/config.rb +75 -0
  33. data/lib/wurk/unique_jobs/constants.rb +53 -0
  34. data/lib/wurk/unique_jobs/digests.rb +169 -0
  35. data/lib/wurk/unique_jobs/errors.rb +71 -0
  36. data/lib/wurk/unique_jobs/job.rb +226 -0
  37. data/lib/wurk/unique_jobs/lock.rb +345 -0
  38. data/lib/wurk/unique_jobs/lock_refresh.rb +98 -0
  39. data/lib/wurk/unique_jobs/locksmith.rb +240 -0
  40. data/lib/wurk/unique_jobs/middleware.rb +109 -0
  41. data/lib/wurk/unique_jobs/on_conflict.rb +107 -0
  42. data/lib/wurk/unique_jobs/orphans.rb +258 -0
  43. data/lib/wurk/unique_jobs/reflections.rb +72 -0
  44. data/lib/wurk/unique_jobs/require/sidekiq-unique-jobs.rb +6 -0
  45. data/lib/wurk/unique_jobs/require/sidekiq_unique_jobs/web.rb +8 -0
  46. data/lib/wurk/unique_jobs/require/sidekiq_unique_jobs.rb +5 -0
  47. data/lib/wurk/unique_jobs/sidekiq_unique_jobs.rb +15 -0
  48. data/lib/wurk/unique_jobs/web/views/_paging.erb +10 -0
  49. data/lib/wurk/unique_jobs/web/views/changelogs.erb +62 -0
  50. data/lib/wurk/unique_jobs/web/views/lock.erb +110 -0
  51. data/lib/wurk/unique_jobs/web/views/locks.erb +61 -0
  52. data/lib/wurk/unique_jobs/web.rb +150 -0
  53. data/lib/wurk/unique_jobs.rb +151 -0
  54. data/lib/wurk/unique_jobs_compat.rb +44 -3
  55. data/lib/wurk/version.rb +1 -1
  56. data/lib/wurk/web/dashboard/api_actions.rb +1 -2
  57. data/lib/wurk/web/enterprise.rb +23 -0
  58. data/lib/wurk.rb +3 -1
  59. data/vendor/assets/dashboard/assets/{ArgsValue-s6SvnYnn.js → ArgsValue-8zbIUK63.js} +1 -1
  60. data/vendor/assets/dashboard/assets/ArgsValue-8zbIUK63.js.br +0 -0
  61. data/vendor/assets/dashboard/assets/ArgsValue-8zbIUK63.js.gz +0 -0
  62. data/vendor/assets/dashboard/assets/{BatchDetail-CprIJHVF.js → BatchDetail-B7FnhWOm.js} +1 -1
  63. data/vendor/assets/dashboard/assets/BatchDetail-B7FnhWOm.js.br +0 -0
  64. data/vendor/assets/dashboard/assets/BatchDetail-B7FnhWOm.js.gz +0 -0
  65. data/vendor/assets/dashboard/assets/{Batches-_UtmkdcL.js → Batches-KBN4rVe3.js} +1 -1
  66. data/vendor/assets/dashboard/assets/Batches-KBN4rVe3.js.br +0 -0
  67. data/vendor/assets/dashboard/assets/Batches-KBN4rVe3.js.gz +0 -0
  68. data/vendor/assets/dashboard/assets/{Busy-CxUt_KaT.js → Busy-Gz7qEa1m.js} +1 -1
  69. data/vendor/assets/dashboard/assets/Busy-Gz7qEa1m.js.br +0 -0
  70. data/vendor/assets/dashboard/assets/Busy-Gz7qEa1m.js.gz +0 -0
  71. data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js +1 -0
  72. data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js.br +0 -0
  73. data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js.gz +0 -0
  74. data/vendor/assets/dashboard/assets/{Dashboard-BpeXrgWN.js → Dashboard-BfVW4Db7.js} +1 -1
  75. data/vendor/assets/dashboard/assets/Dashboard-BfVW4Db7.js.br +0 -0
  76. data/vendor/assets/dashboard/assets/Dashboard-BfVW4Db7.js.gz +0 -0
  77. data/vendor/assets/dashboard/assets/{Dead-DxG8m9Ea.js → Dead-i929U3Al.js} +1 -1
  78. data/vendor/assets/dashboard/assets/Dead-i929U3Al.js.br +0 -0
  79. data/vendor/assets/dashboard/assets/Dead-i929U3Al.js.gz +0 -0
  80. data/vendor/assets/dashboard/assets/{Extension-Bdw1AWK9.js → Extension-DtT_BQGI.js} +1 -1
  81. data/vendor/assets/dashboard/assets/Extension-DtT_BQGI.js.br +0 -0
  82. data/vendor/assets/dashboard/assets/Extension-DtT_BQGI.js.gz +0 -0
  83. data/vendor/assets/dashboard/assets/{FlowDetail-BbLiOUVq.js → FlowDetail-dSxWLJwW.js} +1 -1
  84. data/vendor/assets/dashboard/assets/FlowDetail-dSxWLJwW.js.br +0 -0
  85. data/vendor/assets/dashboard/assets/FlowDetail-dSxWLJwW.js.gz +0 -0
  86. data/vendor/assets/dashboard/assets/{Flows-Cdh5HxbD.js → Flows-DBXdrnl_.js} +1 -1
  87. data/vendor/assets/dashboard/assets/Flows-DBXdrnl_.js.br +0 -0
  88. data/vendor/assets/dashboard/assets/Flows-DBXdrnl_.js.gz +0 -0
  89. data/vendor/assets/dashboard/assets/{JobDetailModal-DyrUaaGZ.js → JobDetailModal-wz97ZwuO.js} +1 -1
  90. data/vendor/assets/dashboard/assets/JobDetailModal-wz97ZwuO.js.br +0 -0
  91. data/vendor/assets/dashboard/assets/JobDetailModal-wz97ZwuO.js.gz +0 -0
  92. data/vendor/assets/dashboard/assets/{Limiters-D7r6cfSD.js → Limiters-LLzkwl5z.js} +1 -1
  93. data/vendor/assets/dashboard/assets/Limiters-LLzkwl5z.js.br +0 -0
  94. data/vendor/assets/dashboard/assets/Limiters-LLzkwl5z.js.gz +0 -0
  95. data/vendor/assets/dashboard/assets/{Metrics-BLenaRy4.js → Metrics-C0ilxg59.js} +1 -1
  96. data/vendor/assets/dashboard/assets/Metrics-C0ilxg59.js.br +0 -0
  97. data/vendor/assets/dashboard/assets/Metrics-C0ilxg59.js.gz +0 -0
  98. data/vendor/assets/dashboard/assets/{NotFound-P0HnKG_i.js → NotFound-CHPpvK-n.js} +1 -1
  99. data/vendor/assets/dashboard/assets/NotFound-CHPpvK-n.js.br +0 -0
  100. data/vendor/assets/dashboard/assets/NotFound-CHPpvK-n.js.gz +0 -0
  101. data/vendor/assets/dashboard/assets/{PageHeader-Dr0x5uFD.js → PageHeader-CGep_jFP.js} +1 -1
  102. data/vendor/assets/dashboard/assets/PageHeader-CGep_jFP.js.br +0 -0
  103. data/vendor/assets/dashboard/assets/PageHeader-CGep_jFP.js.gz +0 -0
  104. data/vendor/assets/dashboard/assets/{Profiles-DwBcuGsp.js → Profiles-D_59KJVX.js} +1 -1
  105. data/vendor/assets/dashboard/assets/Profiles-D_59KJVX.js.br +0 -0
  106. data/vendor/assets/dashboard/assets/Profiles-D_59KJVX.js.gz +0 -0
  107. data/vendor/assets/dashboard/assets/{Queues-BpB_QfMT.js → Queues-B84cTtnr.js} +1 -1
  108. data/vendor/assets/dashboard/assets/Queues-B84cTtnr.js.br +0 -0
  109. data/vendor/assets/dashboard/assets/Queues-B84cTtnr.js.gz +0 -0
  110. data/vendor/assets/dashboard/assets/{RefreshError-CFF9cD72.js → RefreshError-LAOkINDS.js} +1 -1
  111. data/vendor/assets/dashboard/assets/RefreshError-LAOkINDS.js.br +2 -0
  112. data/vendor/assets/dashboard/assets/RefreshError-LAOkINDS.js.gz +0 -0
  113. data/vendor/assets/dashboard/assets/{Retries-CvpBa3nA.js → Retries-sdTIe5PU.js} +1 -1
  114. data/vendor/assets/dashboard/assets/Retries-sdTIe5PU.js.br +0 -0
  115. data/vendor/assets/dashboard/assets/Retries-sdTIe5PU.js.gz +0 -0
  116. data/vendor/assets/dashboard/assets/{Scheduled-B5_rNwmD.js → Scheduled-mWorUG81.js} +1 -1
  117. data/vendor/assets/dashboard/assets/Scheduled-mWorUG81.js.br +0 -0
  118. data/vendor/assets/dashboard/assets/Scheduled-mWorUG81.js.gz +0 -0
  119. data/vendor/assets/dashboard/assets/{Search-DBiXXQ1X.js → Search-DQg2ky9F.js} +1 -1
  120. data/vendor/assets/dashboard/assets/Search-DQg2ky9F.js.br +0 -0
  121. data/vendor/assets/dashboard/assets/Search-DQg2ky9F.js.gz +0 -0
  122. data/vendor/assets/dashboard/assets/{charts-BowrQgy3.js → charts-D2ZSzfcT.js} +1 -1
  123. data/vendor/assets/dashboard/assets/charts-D2ZSzfcT.js.br +0 -0
  124. data/vendor/assets/dashboard/assets/charts-D2ZSzfcT.js.gz +0 -0
  125. data/vendor/assets/dashboard/assets/{index-lb7Hct36.js → index-CYxK_mMH.js} +2 -2
  126. data/vendor/assets/dashboard/assets/index-CYxK_mMH.js.br +0 -0
  127. data/vendor/assets/dashboard/assets/index-CYxK_mMH.js.gz +0 -0
  128. data/vendor/assets/dashboard/assets/{useJobSetList-DOJEPjtn.js → useJobSetList-Bq8gXURX.js} +1 -1
  129. data/vendor/assets/dashboard/assets/useJobSetList-Bq8gXURX.js.br +0 -0
  130. data/vendor/assets/dashboard/assets/useJobSetList-Bq8gXURX.js.gz +0 -0
  131. data/vendor/assets/dashboard/assets/{useResetPageOnEmpty-BkhAVjcM.js → useResetPageOnEmpty-DBe-fKXL.js} +1 -1
  132. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DBe-fKXL.js.br +0 -0
  133. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DBe-fKXL.js.gz +0 -0
  134. data/vendor/assets/dashboard/assets/{useSort-BH4O54LC.js → useSort-CB33x7jI.js} +1 -1
  135. data/vendor/assets/dashboard/assets/useSort-CB33x7jI.js.br +2 -0
  136. data/vendor/assets/dashboard/assets/useSort-CB33x7jI.js.gz +0 -0
  137. data/vendor/assets/dashboard/assets/{utils-5e3YBxoh.js → utils-DvEdG1B-.js} +1 -1
  138. data/vendor/assets/dashboard/assets/utils-DvEdG1B-.js.br +0 -0
  139. data/vendor/assets/dashboard/assets/utils-DvEdG1B-.js.gz +0 -0
  140. data/vendor/assets/dashboard/index.html +1 -1
  141. data/vendor/assets/dashboard/wurk-manifest.json +2 -2
  142. metadata +128 -82
  143. data/vendor/assets/dashboard/assets/ArgsValue-s6SvnYnn.js.br +0 -0
  144. data/vendor/assets/dashboard/assets/ArgsValue-s6SvnYnn.js.gz +0 -0
  145. data/vendor/assets/dashboard/assets/BatchDetail-CprIJHVF.js.br +0 -0
  146. data/vendor/assets/dashboard/assets/BatchDetail-CprIJHVF.js.gz +0 -0
  147. data/vendor/assets/dashboard/assets/Batches-_UtmkdcL.js.br +0 -0
  148. data/vendor/assets/dashboard/assets/Batches-_UtmkdcL.js.gz +0 -0
  149. data/vendor/assets/dashboard/assets/Busy-CxUt_KaT.js.br +0 -0
  150. data/vendor/assets/dashboard/assets/Busy-CxUt_KaT.js.gz +0 -0
  151. data/vendor/assets/dashboard/assets/Cron-BO4CLzcL.js +0 -1
  152. data/vendor/assets/dashboard/assets/Cron-BO4CLzcL.js.br +0 -0
  153. data/vendor/assets/dashboard/assets/Cron-BO4CLzcL.js.gz +0 -0
  154. data/vendor/assets/dashboard/assets/Dashboard-BpeXrgWN.js.br +0 -0
  155. data/vendor/assets/dashboard/assets/Dashboard-BpeXrgWN.js.gz +0 -0
  156. data/vendor/assets/dashboard/assets/Dead-DxG8m9Ea.js.br +0 -0
  157. data/vendor/assets/dashboard/assets/Dead-DxG8m9Ea.js.gz +0 -0
  158. data/vendor/assets/dashboard/assets/Extension-Bdw1AWK9.js.br +0 -0
  159. data/vendor/assets/dashboard/assets/Extension-Bdw1AWK9.js.gz +0 -0
  160. data/vendor/assets/dashboard/assets/FlowDetail-BbLiOUVq.js.br +0 -0
  161. data/vendor/assets/dashboard/assets/FlowDetail-BbLiOUVq.js.gz +0 -0
  162. data/vendor/assets/dashboard/assets/Flows-Cdh5HxbD.js.br +0 -0
  163. data/vendor/assets/dashboard/assets/Flows-Cdh5HxbD.js.gz +0 -0
  164. data/vendor/assets/dashboard/assets/JobDetailModal-DyrUaaGZ.js.br +0 -0
  165. data/vendor/assets/dashboard/assets/JobDetailModal-DyrUaaGZ.js.gz +0 -0
  166. data/vendor/assets/dashboard/assets/Limiters-D7r6cfSD.js.br +0 -0
  167. data/vendor/assets/dashboard/assets/Limiters-D7r6cfSD.js.gz +0 -0
  168. data/vendor/assets/dashboard/assets/Metrics-BLenaRy4.js.br +0 -0
  169. data/vendor/assets/dashboard/assets/Metrics-BLenaRy4.js.gz +0 -0
  170. data/vendor/assets/dashboard/assets/NotFound-P0HnKG_i.js.br +0 -0
  171. data/vendor/assets/dashboard/assets/NotFound-P0HnKG_i.js.gz +0 -0
  172. data/vendor/assets/dashboard/assets/PageHeader-Dr0x5uFD.js.br +0 -0
  173. data/vendor/assets/dashboard/assets/PageHeader-Dr0x5uFD.js.gz +0 -0
  174. data/vendor/assets/dashboard/assets/Profiles-DwBcuGsp.js.br +0 -0
  175. data/vendor/assets/dashboard/assets/Profiles-DwBcuGsp.js.gz +0 -0
  176. data/vendor/assets/dashboard/assets/Queues-BpB_QfMT.js.br +0 -0
  177. data/vendor/assets/dashboard/assets/Queues-BpB_QfMT.js.gz +0 -0
  178. data/vendor/assets/dashboard/assets/RefreshError-CFF9cD72.js.br +0 -0
  179. data/vendor/assets/dashboard/assets/RefreshError-CFF9cD72.js.gz +0 -0
  180. data/vendor/assets/dashboard/assets/Retries-CvpBa3nA.js.br +0 -0
  181. data/vendor/assets/dashboard/assets/Retries-CvpBa3nA.js.gz +0 -0
  182. data/vendor/assets/dashboard/assets/Scheduled-B5_rNwmD.js.br +0 -0
  183. data/vendor/assets/dashboard/assets/Scheduled-B5_rNwmD.js.gz +0 -0
  184. data/vendor/assets/dashboard/assets/Search-DBiXXQ1X.js.br +0 -0
  185. data/vendor/assets/dashboard/assets/Search-DBiXXQ1X.js.gz +0 -0
  186. data/vendor/assets/dashboard/assets/charts-BowrQgy3.js.br +0 -0
  187. data/vendor/assets/dashboard/assets/charts-BowrQgy3.js.gz +0 -0
  188. data/vendor/assets/dashboard/assets/index-lb7Hct36.js.br +0 -0
  189. data/vendor/assets/dashboard/assets/index-lb7Hct36.js.gz +0 -0
  190. data/vendor/assets/dashboard/assets/useJobSetList-DOJEPjtn.js.br +0 -0
  191. data/vendor/assets/dashboard/assets/useJobSetList-DOJEPjtn.js.gz +0 -0
  192. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-BkhAVjcM.js.br +0 -0
  193. data/vendor/assets/dashboard/assets/useResetPageOnEmpty-BkhAVjcM.js.gz +0 -0
  194. data/vendor/assets/dashboard/assets/useSort-BH4O54LC.js.br +0 -0
  195. data/vendor/assets/dashboard/assets/useSort-BH4O54LC.js.gz +0 -0
  196. data/vendor/assets/dashboard/assets/utils-5e3YBxoh.js.br +0 -0
  197. data/vendor/assets/dashboard/assets/utils-5e3YBxoh.js.gz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38e891f5c26931fc61deb3b165cc5a7c4e9c952ee7ed98e2ba121bc89c06476f
4
- data.tar.gz: '09c9fb93ef3cbe927925d714138c98dd3795977c9bc775806b90338adcdf5d00'
3
+ metadata.gz: baff6a3f75bca45d6dbcbed8c3363b306ef0f37f8c48f9de0fac68f320ab9a79
4
+ data.tar.gz: 3e1725ade18090f1d9eca95d0d3b016db9a15747f63bed75b4ef6cc95555982e
5
5
  SHA512:
6
- metadata.gz: dbbd540b3082626c6de579a8dfc841bf27e0c51344a023f9be30a7f411e5021647c5fb531147fe1fbeaee706bb8e6c8a174195ec3c2b741c70b47cbcb80487d6
7
- data.tar.gz: b994abcc5dba5e22aeb892d46a4f619540eec963546ded5456f1d6dd3eca47d0232d5db41b7b31717c9a69ef9fc703579d31439f91814f03a961eadb41324d48
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.17.1", 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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `require "sidekiq/cron/web"`. The gem's file registers the gem's tab when the
4
+ # gem is bundled. Native entries need no extension: the dashboard's own Cron
5
+ # page lists them beside the periodic loops (Wurk::SidekiqCron::WebRows).
6
+ if (spec = Gem.loaded_specs['sidekiq-cron'])
7
+ require File.join(spec.full_gem_path, 'lib/sidekiq/cron/web.rb')
8
+ else
9
+ require_relative '../../wurk/sidekiq_cron'
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `require "sidekiq/cron"`. With the sidekiq-cron gem in the bundle this is the
4
+ # gem's own file, whichever copy the load path finds first; without it, wurk's
5
+ # native implementation (lib/wurk/sidekiq_cron.rb) defines `Sidekiq::Cron`.
6
+ if (spec = Gem.loaded_specs['sidekiq-cron'])
7
+ require File.join(spec.full_gem_path, 'lib/sidekiq/cron.rb')
8
+ else
9
+ require_relative '../wurk/sidekiq_cron'
10
+ end
@@ -0,0 +1,11 @@
1
+ # rubocop:disable Naming/FileName -- the gem's own require name, hyphen included
2
+ # frozen_string_literal: true
3
+
4
+ # `require "sidekiq-cron"`, the gem's entrypoint (Bundler's auto-require).
5
+ # Bundled, the gem loads itself; otherwise wurk's native sidekiq-cron does.
6
+ if (spec = Gem.loaded_specs['sidekiq-cron'])
7
+ require File.join(spec.full_gem_path, 'lib/sidekiq-cron.rb')
8
+ else
9
+ require_relative 'wurk/sidekiq_cron'
10
+ end
11
+ # rubocop:enable Naming/FileName
@@ -69,17 +69,19 @@ module Wurk
69
69
  end
70
70
  end
71
71
 
72
- # Without the gem's middleware the option does nothing: the "unique" job
73
- # simply enqueues twice. Only classes the app has loaded by now are seen.
74
- def warn_on_ignored_locks(logger)
75
- return if defined?(::SidekiqUniqueJobs)
72
+ # Without a unique-jobs client middleware the option does nothing: the
73
+ # "unique" job simply enqueues twice. Either copy's counts, the gem's or
74
+ # Wurk's native one. Only classes the app has loaded by now are seen.
75
+ def warn_on_ignored_locks(logger, chain = Wurk.configuration.client_middleware)
76
+ return if UniqueJobsCompat.client_middleware?(chain)
76
77
 
77
78
  classes = locked_job_classes
78
79
  return if classes.empty?
79
80
 
80
81
  logger.warn do
81
- 'These jobs set `lock:` but sidekiq-unique-jobs is not loaded, so the option does nothing and ' \
82
- "duplicates will run: #{listing(classes)}. Keep the gem, or move them to `unique_for:`."
82
+ 'These jobs set `lock:` but no client middleware takes their locks, so the option does nothing and ' \
83
+ "duplicates will run: #{listing(classes)}. Add it once, in an initializer: " \
84
+ '`chain.add SidekiqUniqueJobs::Middleware::Client` (docs/unique-jobs.md).'
83
85
  end
84
86
  end
85
87
 
data/lib/wurk/compat.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Sidekiq aliases. This is the drop-in contract — every public Wurk::*
4
- # class is exposed under its Sidekiq::* name except two deliberate
5
- # exclusions, `Sidekiq::Cron` and `Sidekiq::Status` (#204): those namespaces
6
- # belong to the third-party sidekiq-cron / sidekiq-status gems, not to
7
- # Sidekiq itself. Never break the rest.
4
+ # class is exposed under its Sidekiq::* name except two namespaces that
5
+ # belong to third-party gems (#204): `Sidekiq::Status` is never defined, and
6
+ # `Sidekiq::Cron` is wurk's native sidekiq-cron only when that gem is not
7
+ # bundled. Never break the rest.
8
8
  #
9
9
  # Spec: docs/target/sidekiq-{free,pro,ent}.md.
10
10
 
@@ -17,13 +17,13 @@ require_relative 'loader'
17
17
  # {Wurk.configure_server}; `Sidekiq::Batch`, `Sidekiq::Limiter`,
18
18
  # `Sidekiq::Client`, `Sidekiq::Pro::Web`, `Sidekiq::Enterprise` all resolve to
19
19
  # their Wurk implementations. This alias surface is the drop-in contract and is
20
- # never broken. Two names are deliberately NOT aliased (#204): `Sidekiq::Cron`
21
- # and `Sidekiq::Status` — those namespaces belong to the third-party
22
- # sidekiq-cron / sidekiq-status gems. `sidekiq-cron` owns `Sidekiq::Cron`, and
23
- # squatting it made the gem's own Poller/Job classes collide at load;
24
- # `sidekiq-status` opens `module Sidekiq::Status`, which resolves the constant
25
- # instead of defining it, so the alias would hand the gem {Wurk::Status} to
26
- # reopen and clobber. The guard comments at `CronParser` and `Status` below
20
+ # never broken. Two names belong to third-party gems (#204): `Sidekiq::Cron`
21
+ # and `Sidekiq::Status`. `sidekiq-cron` owns `Sidekiq::Cron` when it is
22
+ # bundled — squatting it made the gem's own Poller/Job classes collide at
23
+ # load — so wurk's native one (Wurk::SidekiqCron) is only an autoload, and
24
+ # only when the gem is absent. `sidekiq-status` opens `module Sidekiq::Status`,
25
+ # which resolves the constant instead of defining it, so the alias would hand
26
+ # the gem {Wurk::Status} to reopen and clobber. The guard comments at `CronParser` and `Status` below
27
27
  # carry the full rationale.
28
28
  #
29
29
  # @example The same code targets Sidekiq or Wurk unchanged
@@ -175,10 +175,13 @@ module Sidekiq
175
175
  # and iterable_job.rb require subfiles that reopen the class before defining
176
176
  # it, which a direct require would turn into a circular one.
177
177
  #
178
- # No `Sidekiq::Cron` alias on purpose (#204): real Sidekiq never defines it
179
- # — that namespace belongs to the third-party sidekiq-cron gem, and squatting
180
- # it made the gem's own classes (Poller, Job) collide at load. Wurk's native
181
- # periodic surface is `Sidekiq::Periodic` (Ent parity) / `Wurk::Cron`.
178
+ # `Sidekiq::Cron` is not an alias (#204): real Sidekiq never defines it —
179
+ # that namespace belongs to the sidekiq-cron gem, and squatting it made the
180
+ # gem's own classes (Poller, Job) collide at load. With the gem bundled it is
181
+ # left alone. Without it, the name autoloads wurk's native sidekiq-cron
182
+ # (Wurk::SidekiqCron, lib/sidekiq/cron.rb), so an app that dropped the gem
183
+ # keeps its `Sidekiq::Cron::Job` calls and its Redis state. Wurk's Ent
184
+ # periodic surface is `Sidekiq::Periodic` / `Wurk::Cron`.
182
185
  #
183
186
  # `Flow` is a Wurk extra, not parity — aliased because nothing else claims
184
187
  # the name. Checked before adding it, the way `Sidekiq::Cron` (#204) and
@@ -199,6 +202,7 @@ module Sidekiq
199
202
  Deploy: 'compat/deploy', Encryption: 'compat/encryption'
200
203
  )
201
204
  Wurk::LazyLoader.register(Pro, Web: 'compat/web', BatchStatus: 'compat/web')
205
+ autoload :Cron, File.expand_path('../sidekiq/cron.rb', __dir__) unless Gem.loaded_specs.key?('sidekiq-cron')
202
206
 
203
207
  # Top-level Sidekiq.configure_server / configure_client / redis / logger
204
208
  # delegate to Wurk's class methods. Third-party gems treat these as the
@@ -101,12 +101,13 @@ module Wurk
101
101
  # until_and_while_executing job takes its base lock back when an error
102
102
  # crosses it, on top of the `:RUN` lock it may still hold.
103
103
  def release_unique_locks(job)
104
- digests(job).each { |digest| ::SidekiqUniqueJobs::Locksmith.new(job.merge('lock_digest' => digest)).unlock }
104
+ locksmith = UniqueJobsCompat.locksmith_class
105
+ digests(job).each { |digest| locksmith.new(job.merge('lock_digest' => digest)).unlock }
105
106
  end
106
107
 
107
108
  def digests(job)
108
109
  digest = job['lock_digest']
109
- return [] unless digest && job['lock'].to_s != KEEPS_LOCK && defined?(::SidekiqUniqueJobs::Locksmith)
110
+ return [] unless digest && job['lock'].to_s != KEEPS_LOCK && UniqueJobsCompat.locksmith_class
110
111
 
111
112
  base = digest.delete_suffix(RUN_SUFFIX)
112
113
  [base, "#{base}#{RUN_SUFFIX}"]
data/lib/wurk/launcher.rb CHANGED
@@ -62,7 +62,7 @@ module Wurk
62
62
  KILL_JOIN = 0.25
63
63
 
64
64
  attr_accessor :managers, :poller, :periodic_poller, :metrics_rollup, :queue_rollup, :metrics_flusher, :history,
65
- :queue_consumers
65
+ :queue_consumers, :sidekiq_cron_poller
66
66
 
67
67
  def initialize(config, embedded: false)
68
68
  @config = config
@@ -361,7 +361,7 @@ module Wurk
361
361
  # history snapshotter is opt-in and an embedded boot may have stripped the
362
362
  # rest.
363
363
  def start_periodic_components
364
- [@poller, @leader, @periodic_poller, @metrics_rollup,
364
+ [@poller, @leader, @periodic_poller, @sidekiq_cron_poller, @metrics_rollup,
365
365
  @queue_rollup, @queue_consumers, @metrics_flusher, @history].compact.each(&:start)
366
366
  end
367
367
 
@@ -369,8 +369,8 @@ module Wurk
369
369
  # for it (the flusher also writes its last window): side by side, every loop
370
370
  # hears the stop whatever another is stuck on. Returns the threads.
371
371
  def stop_periodic_components
372
- stops = [@metrics_flusher, @periodic_poller, @metrics_rollup, @queue_rollup, @queue_consumers,
373
- @history].compact.map { |t| [t.class, -> { t.terminate }] }
372
+ stops = [@metrics_flusher, @periodic_poller, @sidekiq_cron_poller, @metrics_rollup, @queue_rollup,
373
+ @queue_consumers, @history].compact.map { |t| [t.class, -> { t.terminate }] }
374
374
  stops << ['reaper', -> { @reaper.stop }] if @reaper
375
375
  stops.map do |label, stop|
376
376
  Thread.new { teardown_step(label, &stop) }.tap { |thread| thread.report_on_exception = false }
@@ -545,6 +545,8 @@ module Wurk
545
545
  #
546
546
  # poller / reaper every process, work shared through Redis
547
547
  # periodic_poller leader only enqueues — that is the exactly-once guard
548
+ # sidekiq_cron_poller native sidekiq-cron (Wurk::SidekiqCron), only when
549
+ # loaded and the gem is not; leader only, like the above
548
550
  # metrics_rollup leader only writes the cluster-total chart buckets
549
551
  # (cadence: `config.metrics_rollup_interval`)
550
552
  # queue_rollup leader only writes the `qm|…` per-queue gauges
@@ -558,6 +560,7 @@ module Wurk
558
560
  # Not @cron_poller: sidekiq-cron's Launcher prepend assigns that ivar and
559
561
  # owns its lifecycle. Both pollers run, each over its own registrations.
560
562
  @periodic_poller = Wurk::Cron::Poller.new(@config)
563
+ @sidekiq_cron_poller = Wurk::SidekiqCron::Poller.new(@config) if sidekiq_cron_polls?
561
564
  @metrics_rollup = Wurk::Metrics::Rollup.new(@config)
562
565
  @queue_rollup = Wurk::Metrics::QueueRollup.new(@config)
563
566
  @queue_consumers = Wurk::QueueConsumers::Watch.new(@config)
@@ -565,6 +568,14 @@ module Wurk
565
568
  @history = Wurk::History.new(@config) if @config.history_enabled?
566
569
  end
567
570
 
571
+ # The app loaded `Sidekiq::Cron` and it is wurk's: the gem, when bundled,
572
+ # prepends its own poller onto this class. A poll interval of 0 turns it
573
+ # off, as in the gem.
574
+ def sidekiq_cron_polls?
575
+ defined?(Wurk::SidekiqCron) && Wurk::SidekiqCron.active? &&
576
+ Wurk::SidekiqCron.configuration.cron_poll_interval.to_i.positive?
577
+ end
578
+
568
579
  # Filled in by #run. Declared up front so #initialize reads as the full
569
580
  # inventory of what a Launcher owns.
570
581
  def reset_thread_state
@@ -0,0 +1,5 @@
1
+ -- sidekiq-unique-jobs 8.x delete.lua: drop one digest's queue-time keys and its
2
+ -- `uniquejobs:digests` entry. Every key is in KEYS.
3
+ -- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
4
+ local count = redis.call("ZREM", KEYS[7], KEYS[1])
5
+ return count + redis.call("UNLINK", KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5])
@@ -0,0 +1,6 @@
1
+ -- sidekiq-unique-jobs 8.x delete_by_digest.lua: the queue-time and run-time keys
2
+ -- of one digest, and its entry in the index the caller names. Every key is in KEYS.
3
+ -- KEYS = [digest, queued, primed, locked, run_digest, run_queued, run_primed, run_locked, index]
4
+ local count = redis.call("UNLINK", KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5], KEYS[6], KEYS[7], KEYS[8])
5
+ redis.call("ZREM", KEYS[9], KEYS[1])
6
+ return count
@@ -0,0 +1,42 @@
1
+ -- sidekiq-unique-jobs 8.x delete_job_by_digest.lua (on_conflict: :replace): remove
2
+ -- the first job carrying the digest from its queue, else the schedule, else the
3
+ -- retry set, and return its payload. The gem's copy reads `uniquejobs:digests`
4
+ -- without declaring it, which Dragonfly and a strict Redis refuse; here it is KEYS[4].
5
+ -- KEYS = [queue:<name>, schedule, retry, uniquejobs:digests]
6
+ -- ARGV = [digest]
7
+ local digest = ARGV[1]
8
+ local per = 50
9
+
10
+ local total = redis.call("LLEN", KEYS[1])
11
+ for index = 0, total, per do
12
+ local items = redis.call("LRANGE", KEYS[1], index, index + per - 1)
13
+ if #items == 0 then break end
14
+ for _, item in ipairs(items) do
15
+ if string.find(item, digest, 1, true) then
16
+ redis.call("LREM", KEYS[1], 1, item)
17
+ return item
18
+ end
19
+ end
20
+ end
21
+
22
+ local score = redis.call("ZSCORE", KEYS[4], digest)
23
+ for set = 2, 3 do
24
+ local name = KEYS[set]
25
+ local size = redis.call("ZCARD", name)
26
+ for offset = 0, size, per do
27
+ local items
28
+ if score then
29
+ items = redis.call("ZRANGE", name, score, "+inf", "BYSCORE", "LIMIT", offset, per)
30
+ else
31
+ items = redis.call("ZRANGE", name, offset, offset + per - 1)
32
+ end
33
+ if #items == 0 then break end
34
+ for _, item in ipairs(items) do
35
+ if string.find(item, digest, 1, true) then
36
+ redis.call("ZREM", name, item)
37
+ return item
38
+ end
39
+ end
40
+ end
41
+ end
42
+ return nil
@@ -0,0 +1,54 @@
1
+ -- sidekiq-unique-jobs 8.x lock.lua: take the lock once the queued jid was primed
2
+ -- (the blocking path). Every key is in KEYS.
3
+ -- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
4
+ -- ARGV = [jid, pttl, lock_type, limit, lock_score, now, max_history, script_name]
5
+ local digest, queued, primed, locked, info, changelog, digests, expiring = KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5], KEYS[6], KEYS[7], KEYS[8]
6
+ local job_id, pttl, lock_type, limit, lock_score = ARGV[1], tonumber(ARGV[2]), ARGV[3], tonumber(ARGV[4]), ARGV[5]
7
+ local now, max_history, script_name = tonumber(ARGV[6]), tonumber(ARGV[7]), ARGV[8]
8
+
9
+ local function log(message, prev_jid)
10
+ if not max_history or max_history == 0 then return end
11
+ local entry = cjson.encode({digest = digest, job_id = job_id, script = script_name, message = message, time = now, prev_jid = prev_jid})
12
+ redis.call("ZADD", changelog, now, entry)
13
+ redis.call("ZREMRANGEBYRANK", changelog, 0, -1 * max_history)
14
+ redis.call("PUBLISH", changelog, entry)
15
+ end
16
+
17
+ local function drop_queued()
18
+ if limit <= 1 then
19
+ redis.call("UNLINK", queued, primed)
20
+ else
21
+ redis.call("LREM", queued, -1, job_id)
22
+ redis.call("LREM", primed, 1, job_id)
23
+ end
24
+ end
25
+
26
+ if redis.call("HEXISTS", locked, job_id) == 1 then
27
+ log("Duplicate")
28
+ drop_queued()
29
+ return job_id
30
+ end
31
+
32
+ if limit <= redis.call("HLEN", locked) then
33
+ log("Limited")
34
+ return nil
35
+ end
36
+
37
+ if lock_type == "until_expired" and pttl and pttl > 0 then
38
+ redis.call("ZADD", expiring, now + pttl, digest)
39
+ else
40
+ local score = lock_score
41
+ if #lock_score == 0 then score = now end
42
+ redis.call("ZADD", digests, score, digest)
43
+ end
44
+ redis.call("HSET", locked, job_id, now)
45
+ drop_queued()
46
+
47
+ if pttl and pttl > 0 then
48
+ redis.call("PEXPIRE", digest, pttl)
49
+ redis.call("PEXPIRE", locked, pttl)
50
+ redis.call("PEXPIRE", info, pttl)
51
+ end
52
+
53
+ log("Locked")
54
+ return job_id
@@ -0,0 +1,43 @@
1
+ -- sidekiq-unique-jobs 8.x queue.lua: claim the digest and queue this jid for the
2
+ -- blocking path (Locksmith#lock with a wait, #execute). Every key is in KEYS.
3
+ -- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
4
+ -- ARGV = [jid, pttl, lock_type, limit, lock_score, now, max_history, script_name]
5
+ local digest, queued, locked, changelog = KEYS[1], KEYS[2], KEYS[4], KEYS[6]
6
+ local job_id, pttl, limit = ARGV[1], tonumber(ARGV[2]), tonumber(ARGV[4])
7
+ local now, max_history, script_name = tonumber(ARGV[6]), tonumber(ARGV[7]), ARGV[8]
8
+
9
+ local function log(message, prev_jid)
10
+ if not max_history or max_history == 0 then return end
11
+ local entry = cjson.encode({digest = digest, job_id = job_id, script = script_name, message = message, time = now, prev_jid = prev_jid})
12
+ redis.call("ZADD", changelog, now, entry)
13
+ redis.call("ZREMRANGEBYRANK", changelog, 0, -1 * max_history)
14
+ redis.call("PUBLISH", changelog, entry)
15
+ end
16
+
17
+ if redis.call("HEXISTS", locked, job_id) == 1 then
18
+ log("Duplicate")
19
+ return job_id
20
+ end
21
+
22
+ if not redis.call("SET", digest, job_id, "NX") then
23
+ local prev_jid = redis.call("GET", digest)
24
+ if prev_jid == job_id then
25
+ log("Duplicate")
26
+ return job_id
27
+ end
28
+ if limit > redis.call("HLEN", locked) and redis.call("LLEN", queued) < limit then
29
+ redis.call("SET", digest, job_id)
30
+ else
31
+ log("Limit exceeded", prev_jid)
32
+ return prev_jid
33
+ end
34
+ end
35
+
36
+ redis.call("LPUSH", queued, job_id)
37
+ if pttl and pttl > 0 then
38
+ redis.call("PEXPIRE", digest, pttl)
39
+ redis.call("PEXPIRE", queued, pttl)
40
+ end
41
+
42
+ log("Queued")
43
+ return job_id
@@ -0,0 +1,67 @@
1
+ -- sidekiq-unique-jobs 8.x queue_and_lock.lua, the same writes to the same keys.
2
+ -- Wurk::UniqueJobs::Locksmith#lock without a wait. Every key it touches is in KEYS.
3
+ -- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
4
+ -- ARGV = [jid, pttl, lock_type, limit, lock_score, now, max_history, script_name]
5
+ local digest, queued, locked, info, changelog, digests, expiring = KEYS[1], KEYS[2], KEYS[4], KEYS[5], KEYS[6], KEYS[7], KEYS[8]
6
+ local job_id, pttl, lock_type, limit, lock_score = ARGV[1], tonumber(ARGV[2]), ARGV[3], tonumber(ARGV[4]), ARGV[5]
7
+ local now, max_history, script_name = tonumber(ARGV[6]), tonumber(ARGV[7]), ARGV[8]
8
+
9
+ local function log(message, prev_jid)
10
+ if not max_history or max_history == 0 then return end
11
+ local entry = cjson.encode({digest = digest, job_id = job_id, script = script_name, message = message, time = now, prev_jid = prev_jid})
12
+ redis.call("ZADD", changelog, now, entry)
13
+ redis.call("ZREMRANGEBYRANK", changelog, 0, -1 * max_history)
14
+ redis.call("PUBLISH", changelog, entry)
15
+ end
16
+
17
+ if limit <= 1 then
18
+ if redis.call("HLEN", locked) > 0 then
19
+ if redis.call("HEXISTS", locked, job_id) == 1 then
20
+ log("Duplicate")
21
+ return job_id
22
+ end
23
+ log("Limited")
24
+ return nil
25
+ end
26
+ redis.call("SET", digest, job_id)
27
+ else
28
+ if redis.call("HEXISTS", locked, job_id) == 1 then
29
+ log("Duplicate")
30
+ return job_id
31
+ end
32
+ if not redis.call("SET", digest, job_id, "NX") then
33
+ local prev_jid = redis.call("GET", digest)
34
+ if prev_jid == job_id then
35
+ log("Duplicate")
36
+ return job_id
37
+ end
38
+ if limit > redis.call("HLEN", locked) and redis.call("LLEN", queued) < limit then
39
+ redis.call("SET", digest, job_id)
40
+ else
41
+ log("Limit exceeded", prev_jid)
42
+ return nil
43
+ end
44
+ end
45
+ if limit <= redis.call("HLEN", locked) then
46
+ log("Limited")
47
+ return nil
48
+ end
49
+ end
50
+
51
+ if lock_type == "until_expired" and pttl and pttl > 0 then
52
+ redis.call("ZADD", expiring, now + pttl, digest)
53
+ else
54
+ local score = lock_score
55
+ if #lock_score == 0 then score = now end
56
+ redis.call("ZADD", digests, score, digest)
57
+ end
58
+ redis.call("HSET", locked, job_id, now)
59
+
60
+ if pttl and pttl > 0 then
61
+ redis.call("PEXPIRE", digest, pttl)
62
+ redis.call("PEXPIRE", locked, pttl)
63
+ redis.call("PEXPIRE", info, pttl)
64
+ end
65
+
66
+ log("Locked")
67
+ return job_id
@@ -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,61 @@
1
+ -- sidekiq-unique-jobs 8.x unlock.lua. Returns the jid when this job held the
2
+ -- lock (or the lock was orphaned), nil while another holder keeps it. The "1"
3
+ -- pushed to QUEUED wakes a job blocked on the lock. Every key is in KEYS.
4
+ -- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
5
+ -- ARGV = [jid, pttl, lock_type, limit, lock_score, now, max_history, script_name, sync_locked]
6
+ local digest, queued, primed, locked, info, changelog, digests = KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5], KEYS[6], KEYS[7]
7
+ local job_id, lock_type, limit = ARGV[1], ARGV[3], tonumber(ARGV[4])
8
+ local now, max_history, script_name, sync_locked = tonumber(ARGV[6]), tonumber(ARGV[7]), ARGV[8], ARGV[9] == "1"
9
+
10
+ local function log(message, prev_jid)
11
+ if not max_history or max_history == 0 then return end
12
+ local entry = cjson.encode({digest = digest, job_id = job_id, script = script_name, message = message, time = now, prev_jid = prev_jid})
13
+ redis.call("ZADD", changelog, now, entry)
14
+ redis.call("ZREMRANGEBYRANK", changelog, 0, -1 * max_history)
15
+ redis.call("PUBLISH", changelog, entry)
16
+ end
17
+
18
+ if sync_locked and limit <= 1 then
19
+ if lock_type ~= "until_expired" then
20
+ redis.call("UNLINK", digest, info, locked, primed)
21
+ end
22
+ redis.call("ZREM", digests, digest)
23
+ log("Unlocked")
24
+ return job_id
25
+ end
26
+
27
+ local holds_lock = redis.call("HEXISTS", locked, job_id) == 1
28
+ if not holds_lock then
29
+ redis.call("LREM", queued, -1, job_id)
30
+ redis.call("LREM", primed, -1, job_id)
31
+ local others = redis.call("LLEN", queued) + redis.call("LLEN", primed) + redis.call("HLEN", locked)
32
+ if others > 0 then
33
+ log("Yielding to other lock holders")
34
+ return nil
35
+ end
36
+ end
37
+
38
+ if lock_type ~= "until_expired" then
39
+ redis.call("HDEL", locked, job_id)
40
+ if limit and limit > 1 then
41
+ local locked_count = redis.call("HLEN", locked)
42
+ redis.call("UNLINK", digest, info)
43
+ if locked_count < 1 then
44
+ redis.call("UNLINK", locked, primed)
45
+ redis.call("ZREM", digests, digest)
46
+ elseif redis.call("LLEN", primed) == 0 then
47
+ redis.call("UNLINK", primed)
48
+ end
49
+ else
50
+ redis.call("UNLINK", digest, info, locked, primed)
51
+ redis.call("ZREM", digests, digest)
52
+ end
53
+ else
54
+ redis.call("ZREM", digests, digest)
55
+ end
56
+
57
+ redis.call("LPUSH", queued, "1")
58
+ redis.call("PEXPIRE", queued, 5000)
59
+
60
+ log("Unlocked")
61
+ return job_id
@@ -174,8 +174,9 @@ module Wurk
174
174
  end
175
175
  return unless counts['gem_locks'].positive?
176
176
 
177
- @report.info('gem_locks', "#{counts['gem_locks']} sidekiq-unique-jobs lock(s). Keep the gem and they carry " \
178
- 'over. Drop it and they stay held: UNLINK `uniquejobs:*` before any rollback.')
177
+ @report.info('gem_locks', "#{counts['gem_locks']} sidekiq-unique-jobs lock(s). They carry over whether " \
178
+ "you keep the gem or drop it: Wurk's native copy reads and releases the same " \
179
+ '`uniquejobs:*` keys. Do not UNLINK them.')
179
180
  end
180
181
 
181
182
  def add_ons(specs)
@@ -190,13 +191,13 @@ module Wurk
190
191
  end
191
192
 
192
193
  def ignored_locks
193
- return if defined?(::SidekiqUniqueJobs)
194
+ return if UniqueJobsCompat.client_middleware?(Wurk.configuration.client_middleware)
194
195
 
195
196
  classes = BootChecks.locked_job_classes
196
197
  return if classes.empty?
197
198
 
198
- @report.warning('ignored_lock', "#{classes.size} class(es) set `lock:` with sidekiq-unique-jobs not loaded, " \
199
- "so duplicates run: #{BootChecks.listing(classes)}.")
199
+ @report.warning('ignored_lock', "#{classes.size} class(es) set `lock:` with no unique-jobs client " \
200
+ "middleware installed, so duplicates run: #{BootChecks.listing(classes)}.")
200
201
  end
201
202
  end
202
203
  end