wurk 1.20.0 → 1.22.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 +4 -4
- data/README.md +1 -1
- data/lib/wurk/api/roll_up.rb +2 -1
- data/lib/wurk/cpu_count.rb +23 -12
- data/lib/wurk/finished_job_cleanup.rb +11 -3
- data/lib/wurk/heartbeat.rb +38 -5
- data/lib/wurk/lazy_loader.rb +1 -1
- data/lib/wurk/lua/unique_jobs_claim.lua +15 -0
- data/lib/wurk/lua/unique_jobs_lock.lua +6 -2
- data/lib/wurk/lua/unique_jobs_refresh.lua +17 -5
- data/lib/wurk/lua/unique_jobs_unlock.lua +24 -4
- data/lib/wurk/manager.rb +91 -26
- data/lib/wurk/memory_limit.rb +42 -0
- data/lib/wurk/metrics/deaths.rb +7 -4
- data/lib/wurk/processor.rb +44 -14
- data/lib/wurk/sidekiq_cron/job/enqueue.rb +24 -0
- data/lib/wurk/sidekiq_cron/job.rb +7 -0
- data/lib/wurk/unique_jobs/lock.rb +22 -7
- data/lib/wurk/unique_jobs/lock_refresh.rb +21 -31
- data/lib/wurk/unique_jobs/locksmith.rb +34 -4
- data/lib/wurk/unique_jobs/middleware.rb +1 -1
- data/lib/wurk/unique_jobs/run.rb +75 -0
- data/lib/wurk/unique_jobs.rb +1 -0
- data/lib/wurk/version.rb +1 -1
- data/lib/wurk/web/dashboard/serializers.rb +2 -0
- data/vendor/assets/dashboard/assets/{ArgsValue-8zbIUK63.js → ArgsValue-DpQn14DK.js} +1 -1
- data/vendor/assets/dashboard/assets/ArgsValue-DpQn14DK.js.br +1 -0
- data/vendor/assets/dashboard/assets/ArgsValue-DpQn14DK.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{BatchDetail-B7FnhWOm.js → BatchDetail-Cypsn561.js} +1 -1
- data/vendor/assets/dashboard/assets/BatchDetail-Cypsn561.js.br +0 -0
- data/vendor/assets/dashboard/assets/BatchDetail-Cypsn561.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Batches-KBN4rVe3.js → Batches-BWZkQ5hD.js} +1 -1
- data/vendor/assets/dashboard/assets/Batches-BWZkQ5hD.js.br +0 -0
- data/vendor/assets/dashboard/assets/Batches-BWZkQ5hD.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Busy-ZmHMw1k8.js +1 -0
- data/vendor/assets/dashboard/assets/Busy-ZmHMw1k8.js.br +0 -0
- data/vendor/assets/dashboard/assets/Busy-ZmHMw1k8.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Cron-B8esPvHL.js → Cron-3VDK-PNz.js} +1 -1
- data/vendor/assets/dashboard/assets/Cron-3VDK-PNz.js.br +0 -0
- data/vendor/assets/dashboard/assets/Cron-3VDK-PNz.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Dashboard-BfVW4Db7.js → Dashboard-DMxGzmtH.js} +1 -1
- data/vendor/assets/dashboard/assets/Dashboard-DMxGzmtH.js.br +0 -0
- data/vendor/assets/dashboard/assets/Dashboard-DMxGzmtH.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Dead-i929U3Al.js → Dead-DeqAO9ZN.js} +1 -1
- data/vendor/assets/dashboard/assets/Dead-DeqAO9ZN.js.br +0 -0
- data/vendor/assets/dashboard/assets/Dead-DeqAO9ZN.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Extension-DtT_BQGI.js → Extension-DWQSMYBp.js} +1 -1
- data/vendor/assets/dashboard/assets/Extension-DWQSMYBp.js.br +0 -0
- data/vendor/assets/dashboard/assets/Extension-DWQSMYBp.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{FilterBox-qrHAQiEp.js → FilterBox-CMLPpIc7.js} +1 -1
- data/vendor/assets/dashboard/assets/FilterBox-CMLPpIc7.js.br +0 -0
- data/vendor/assets/dashboard/assets/FilterBox-CMLPpIc7.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{FlowDetail-dSxWLJwW.js → FlowDetail-D1y87gkJ.js} +1 -1
- data/vendor/assets/dashboard/assets/FlowDetail-D1y87gkJ.js.br +0 -0
- data/vendor/assets/dashboard/assets/FlowDetail-D1y87gkJ.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{FlowState-Cp2exrrY.js → FlowState-CxnwAhh-.js} +1 -1
- data/vendor/assets/dashboard/assets/FlowState-CxnwAhh-.js.br +0 -0
- data/vendor/assets/dashboard/assets/FlowState-CxnwAhh-.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Flows-DBXdrnl_.js → Flows-C6J-HKxx.js} +1 -1
- data/vendor/assets/dashboard/assets/Flows-C6J-HKxx.js.br +0 -0
- data/vendor/assets/dashboard/assets/Flows-C6J-HKxx.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{JobDetailModal-wz97ZwuO.js → JobDetailModal-CZy5HMZa.js} +1 -1
- data/vendor/assets/dashboard/assets/JobDetailModal-CZy5HMZa.js.br +0 -0
- data/vendor/assets/dashboard/assets/JobDetailModal-CZy5HMZa.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Limiters-LLzkwl5z.js → Limiters-DjUfxRZD.js} +1 -1
- data/vendor/assets/dashboard/assets/Limiters-DjUfxRZD.js.br +0 -0
- data/vendor/assets/dashboard/assets/Limiters-DjUfxRZD.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Metrics-C0ilxg59.js → Metrics-n8fxcg8T.js} +1 -1
- data/vendor/assets/dashboard/assets/Metrics-n8fxcg8T.js.br +0 -0
- data/vendor/assets/dashboard/assets/Metrics-n8fxcg8T.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{NotFound-CHPpvK-n.js → NotFound-Dr_8EdUe.js} +1 -1
- data/vendor/assets/dashboard/assets/NotFound-Dr_8EdUe.js.br +0 -0
- data/vendor/assets/dashboard/assets/NotFound-Dr_8EdUe.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{PageHeader-CGep_jFP.js → PageHeader-BAxQtYat.js} +1 -1
- data/vendor/assets/dashboard/assets/PageHeader-BAxQtYat.js.br +0 -0
- data/vendor/assets/dashboard/assets/PageHeader-BAxQtYat.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Profiles-D_59KJVX.js → Profiles-6owt0fLq.js} +1 -1
- data/vendor/assets/dashboard/assets/Profiles-6owt0fLq.js.br +0 -0
- data/vendor/assets/dashboard/assets/Profiles-6owt0fLq.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Queues-B84cTtnr.js → Queues-Vr00MajH.js} +1 -1
- data/vendor/assets/dashboard/assets/Queues-Vr00MajH.js.br +0 -0
- data/vendor/assets/dashboard/assets/Queues-Vr00MajH.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{RefreshError-LAOkINDS.js → RefreshError-BSbC4Wzj.js} +1 -1
- data/vendor/assets/dashboard/assets/RefreshError-BSbC4Wzj.js.br +1 -0
- data/vendor/assets/dashboard/assets/RefreshError-BSbC4Wzj.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Retries-sdTIe5PU.js → Retries-hmBIIc50.js} +1 -1
- data/vendor/assets/dashboard/assets/Retries-hmBIIc50.js.br +0 -0
- data/vendor/assets/dashboard/assets/Retries-hmBIIc50.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Scheduled-mWorUG81.js → Scheduled-C3z_QVRV.js} +1 -1
- data/vendor/assets/dashboard/assets/Scheduled-C3z_QVRV.js.br +0 -0
- data/vendor/assets/dashboard/assets/Scheduled-C3z_QVRV.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{Search-DQg2ky9F.js → Search-BCtA1hRC.js} +1 -1
- data/vendor/assets/dashboard/assets/Search-BCtA1hRC.js.br +0 -0
- data/vendor/assets/dashboard/assets/Search-BCtA1hRC.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{ar-CP7xhN_d.js → ar-3787SQUG.js} +1 -1
- data/vendor/assets/dashboard/assets/ar-3787SQUG.js.br +0 -0
- data/vendor/assets/dashboard/assets/ar-3787SQUG.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{charts-D2ZSzfcT.js → charts-BpMpoJMK.js} +1 -1
- data/vendor/assets/dashboard/assets/charts-BpMpoJMK.js.br +0 -0
- data/vendor/assets/dashboard/assets/charts-BpMpoJMK.js.gz +0 -0
- data/vendor/assets/dashboard/assets/de-CBZHXI2c.js +1 -0
- data/vendor/assets/dashboard/assets/de-CBZHXI2c.js.br +0 -0
- data/vendor/assets/dashboard/assets/de-CBZHXI2c.js.gz +0 -0
- data/vendor/assets/dashboard/assets/es-7R-FBjEM.js +1 -0
- data/vendor/assets/dashboard/assets/es-7R-FBjEM.js.br +0 -0
- data/vendor/assets/dashboard/assets/es-7R-FBjEM.js.gz +0 -0
- data/vendor/assets/dashboard/assets/fr-BWtNzFDs.js +1 -0
- data/vendor/assets/dashboard/assets/fr-BWtNzFDs.js.br +0 -0
- data/vendor/assets/dashboard/assets/fr-BWtNzFDs.js.gz +0 -0
- data/vendor/assets/dashboard/assets/i18n-CcctaZzv.js +1 -0
- data/vendor/assets/dashboard/assets/i18n-CcctaZzv.js.br +0 -0
- data/vendor/assets/dashboard/assets/i18n-CcctaZzv.js.gz +0 -0
- data/vendor/assets/dashboard/assets/index-4RKo4182.js +141 -0
- data/vendor/assets/dashboard/assets/index-4RKo4182.js.br +0 -0
- data/vendor/assets/dashboard/assets/index-4RKo4182.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{index-BX9nblxT.css → index-CDFtNJAE.css} +1 -1
- data/vendor/assets/dashboard/assets/index-CDFtNJAE.css.br +0 -0
- data/vendor/assets/dashboard/assets/{index-BX9nblxT.css.gz → index-CDFtNJAE.css.gz} +0 -0
- data/vendor/assets/dashboard/assets/ja-BxFx7uC9.js +1 -0
- data/vendor/assets/dashboard/assets/ja-BxFx7uC9.js.br +0 -0
- data/vendor/assets/dashboard/assets/ja-BxFx7uC9.js.gz +0 -0
- data/vendor/assets/dashboard/assets/pt-BR-D4UE9nc6.js +1 -0
- data/vendor/assets/dashboard/assets/pt-BR-D4UE9nc6.js.br +0 -0
- data/vendor/assets/dashboard/assets/pt-BR-D4UE9nc6.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{useJobSetList-Bq8gXURX.js → useJobSetList-BDrdWPm7.js} +1 -1
- data/vendor/assets/dashboard/assets/useJobSetList-BDrdWPm7.js.br +0 -0
- data/vendor/assets/dashboard/assets/useJobSetList-BDrdWPm7.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{useResetPageOnEmpty-DBe-fKXL.js → useResetPageOnEmpty-CTcc5SKm.js} +1 -1
- data/vendor/assets/dashboard/assets/useResetPageOnEmpty-CTcc5SKm.js.br +0 -0
- data/vendor/assets/dashboard/assets/useResetPageOnEmpty-CTcc5SKm.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{useSort-CB33x7jI.js → useSort-Cha97Uiw.js} +1 -1
- data/vendor/assets/dashboard/assets/useSort-Cha97Uiw.js.br +0 -0
- data/vendor/assets/dashboard/assets/useSort-Cha97Uiw.js.gz +0 -0
- data/vendor/assets/dashboard/assets/{utils-DvEdG1B-.js → utils-DiZjRmuC.js} +1 -1
- data/vendor/assets/dashboard/assets/utils-DiZjRmuC.js.br +0 -0
- data/vendor/assets/dashboard/assets/utils-DiZjRmuC.js.gz +0 -0
- data/vendor/assets/dashboard/assets/zh-CN-D1new-Xl.js +1 -0
- data/vendor/assets/dashboard/assets/zh-CN-D1new-Xl.js.br +0 -0
- data/vendor/assets/dashboard/assets/zh-CN-D1new-Xl.js.gz +0 -0
- data/vendor/assets/dashboard/index.html +3 -3
- data/vendor/assets/dashboard/wurk-manifest.json +2 -2
- metadata +118 -115
- data/vendor/assets/dashboard/assets/ArgsValue-8zbIUK63.js.br +0 -0
- data/vendor/assets/dashboard/assets/ArgsValue-8zbIUK63.js.gz +0 -0
- data/vendor/assets/dashboard/assets/BatchDetail-B7FnhWOm.js.br +0 -0
- data/vendor/assets/dashboard/assets/BatchDetail-B7FnhWOm.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Batches-KBN4rVe3.js.br +0 -0
- data/vendor/assets/dashboard/assets/Batches-KBN4rVe3.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Busy-Gz7qEa1m.js +0 -1
- data/vendor/assets/dashboard/assets/Busy-Gz7qEa1m.js.br +0 -0
- data/vendor/assets/dashboard/assets/Busy-Gz7qEa1m.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js.br +0 -0
- data/vendor/assets/dashboard/assets/Cron-B8esPvHL.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Dashboard-BfVW4Db7.js.br +0 -0
- data/vendor/assets/dashboard/assets/Dashboard-BfVW4Db7.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Dead-i929U3Al.js.br +0 -0
- data/vendor/assets/dashboard/assets/Dead-i929U3Al.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Extension-DtT_BQGI.js.br +0 -0
- data/vendor/assets/dashboard/assets/Extension-DtT_BQGI.js.gz +0 -0
- data/vendor/assets/dashboard/assets/FilterBox-qrHAQiEp.js.br +0 -0
- data/vendor/assets/dashboard/assets/FilterBox-qrHAQiEp.js.gz +0 -0
- data/vendor/assets/dashboard/assets/FlowDetail-dSxWLJwW.js.br +0 -0
- data/vendor/assets/dashboard/assets/FlowDetail-dSxWLJwW.js.gz +0 -0
- data/vendor/assets/dashboard/assets/FlowState-Cp2exrrY.js.br +0 -2
- data/vendor/assets/dashboard/assets/FlowState-Cp2exrrY.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Flows-DBXdrnl_.js.br +0 -0
- data/vendor/assets/dashboard/assets/Flows-DBXdrnl_.js.gz +0 -0
- data/vendor/assets/dashboard/assets/JobDetailModal-wz97ZwuO.js.br +0 -0
- data/vendor/assets/dashboard/assets/JobDetailModal-wz97ZwuO.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Limiters-LLzkwl5z.js.br +0 -0
- data/vendor/assets/dashboard/assets/Limiters-LLzkwl5z.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Metrics-C0ilxg59.js.br +0 -0
- data/vendor/assets/dashboard/assets/Metrics-C0ilxg59.js.gz +0 -0
- data/vendor/assets/dashboard/assets/NotFound-CHPpvK-n.js.br +0 -0
- data/vendor/assets/dashboard/assets/NotFound-CHPpvK-n.js.gz +0 -0
- data/vendor/assets/dashboard/assets/PageHeader-CGep_jFP.js.br +0 -0
- data/vendor/assets/dashboard/assets/PageHeader-CGep_jFP.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Profiles-D_59KJVX.js.br +0 -0
- data/vendor/assets/dashboard/assets/Profiles-D_59KJVX.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Queues-B84cTtnr.js.br +0 -0
- data/vendor/assets/dashboard/assets/Queues-B84cTtnr.js.gz +0 -0
- data/vendor/assets/dashboard/assets/RefreshError-LAOkINDS.js.br +0 -2
- data/vendor/assets/dashboard/assets/RefreshError-LAOkINDS.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Retries-sdTIe5PU.js.br +0 -0
- data/vendor/assets/dashboard/assets/Retries-sdTIe5PU.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Scheduled-mWorUG81.js.br +0 -0
- data/vendor/assets/dashboard/assets/Scheduled-mWorUG81.js.gz +0 -0
- data/vendor/assets/dashboard/assets/Search-DQg2ky9F.js.br +0 -0
- data/vendor/assets/dashboard/assets/Search-DQg2ky9F.js.gz +0 -0
- data/vendor/assets/dashboard/assets/ar-CP7xhN_d.js.br +0 -0
- data/vendor/assets/dashboard/assets/ar-CP7xhN_d.js.gz +0 -0
- data/vendor/assets/dashboard/assets/charts-D2ZSzfcT.js.br +0 -0
- data/vendor/assets/dashboard/assets/charts-D2ZSzfcT.js.gz +0 -0
- data/vendor/assets/dashboard/assets/de-CESa1rIa.js +0 -1
- data/vendor/assets/dashboard/assets/de-CESa1rIa.js.br +0 -0
- data/vendor/assets/dashboard/assets/de-CESa1rIa.js.gz +0 -0
- data/vendor/assets/dashboard/assets/es-DduN2Y-4.js +0 -1
- data/vendor/assets/dashboard/assets/es-DduN2Y-4.js.br +0 -0
- data/vendor/assets/dashboard/assets/es-DduN2Y-4.js.gz +0 -0
- data/vendor/assets/dashboard/assets/fr-D0g3vgjI.js +0 -1
- data/vendor/assets/dashboard/assets/fr-D0g3vgjI.js.br +0 -0
- data/vendor/assets/dashboard/assets/fr-D0g3vgjI.js.gz +0 -0
- data/vendor/assets/dashboard/assets/i18n-DyFKCgd5.js +0 -1
- data/vendor/assets/dashboard/assets/i18n-DyFKCgd5.js.br +0 -0
- data/vendor/assets/dashboard/assets/i18n-DyFKCgd5.js.gz +0 -0
- data/vendor/assets/dashboard/assets/index-BX9nblxT.css.br +0 -0
- data/vendor/assets/dashboard/assets/index-CYxK_mMH.js +0 -141
- data/vendor/assets/dashboard/assets/index-CYxK_mMH.js.br +0 -0
- data/vendor/assets/dashboard/assets/index-CYxK_mMH.js.gz +0 -0
- data/vendor/assets/dashboard/assets/ja-D04z9gNg.js +0 -1
- data/vendor/assets/dashboard/assets/ja-D04z9gNg.js.br +0 -0
- data/vendor/assets/dashboard/assets/ja-D04z9gNg.js.gz +0 -0
- data/vendor/assets/dashboard/assets/pt-BR-CI0f7zuq.js +0 -1
- data/vendor/assets/dashboard/assets/pt-BR-CI0f7zuq.js.br +0 -0
- data/vendor/assets/dashboard/assets/pt-BR-CI0f7zuq.js.gz +0 -0
- data/vendor/assets/dashboard/assets/useJobSetList-Bq8gXURX.js.br +0 -0
- data/vendor/assets/dashboard/assets/useJobSetList-Bq8gXURX.js.gz +0 -0
- data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DBe-fKXL.js.br +0 -0
- data/vendor/assets/dashboard/assets/useResetPageOnEmpty-DBe-fKXL.js.gz +0 -0
- data/vendor/assets/dashboard/assets/useSort-CB33x7jI.js.br +0 -2
- data/vendor/assets/dashboard/assets/useSort-CB33x7jI.js.gz +0 -0
- data/vendor/assets/dashboard/assets/utils-DvEdG1B-.js.br +0 -0
- data/vendor/assets/dashboard/assets/utils-DvEdG1B-.js.gz +0 -0
- data/vendor/assets/dashboard/assets/zh-CN-Ty7GVN_E.js +0 -1
- data/vendor/assets/dashboard/assets/zh-CN-Ty7GVN_E.js.br +0 -0
- data/vendor/assets/dashboard/assets/zh-CN-Ty7GVN_E.js.gz +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 430e3134ceb5cf8cab1d90c39bd7eea3569d9d0447c6029b713022251f2e2552
|
|
4
|
+
data.tar.gz: 9b6d15b8c55b579f01f0f25293e5f7feb00a5db160f04b55c44a8502ac22a9dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d202085de88fab79b94b84a5754a16ad15442d457ebbd9a42ab423cc1284fb496845d1346f6d8d85cd81aa36cd911974d5a582757ae15373566c8fd2becf4583
|
|
7
|
+
data.tar.gz: 6b67560d2669139c1a949c9840e04d997ad8e9db792f01d1b2d76d6a8bc022ee436a4c13b8e1130e7e4adeb1f85404537d4b56fd491fcdc3bbdb843ed6e8a724
|
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.
|
|
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.22.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
|
|
data/lib/wurk/api/roll_up.rb
CHANGED
|
@@ -96,7 +96,8 @@ module Wurk
|
|
|
96
96
|
{
|
|
97
97
|
hostname: hostname, processes: group.size,
|
|
98
98
|
concurrency: sum(group, 'concurrency'), busy: sum(group, 'busy'), rss_kb: sum(group, 'rss'),
|
|
99
|
-
cpu_model: facts['cpu_model'], cores: facts['cores'], memory_total_kb: facts['memory_total_kb']
|
|
99
|
+
cpu_model: facts['cpu_model'], cores: facts['cores'], memory_total_kb: facts['memory_total_kb'],
|
|
100
|
+
cpu_limit: facts['cpu_limit'], memory_limit_kb: facts['memory_limit_kb']
|
|
100
101
|
}
|
|
101
102
|
end
|
|
102
103
|
|
data/lib/wurk/cpu_count.rb
CHANGED
|
@@ -28,15 +28,25 @@ module Wurk
|
|
|
28
28
|
module_function
|
|
29
29
|
|
|
30
30
|
def detect(root: ROOT, proc_cgroup: PROC_SELF_CGROUP, nprocessors: Etc.nprocessors)
|
|
31
|
-
quota =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
quota, source = quota_with_source(root, proc_cgroup)
|
|
32
|
+
count = quota&.ceil
|
|
33
|
+
return Result.new(nprocessors, 'Etc.nprocessors') if count.nil? || count >= nprocessors
|
|
34
|
+
|
|
35
|
+
Result.new(count, source)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# The quota itself, unrounded (a Rational: 1.5 CPUs stays 3/2), or nil
|
|
39
|
+
# when no cgroup caps the CPU. The Busy page shows this one, beside the
|
|
40
|
+
# host's cores.
|
|
41
|
+
def quota(root: ROOT, proc_cgroup: PROC_SELF_CGROUP)
|
|
42
|
+
quota_with_source(root, proc_cgroup).first
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def quota_with_source(root, proc_cgroup)
|
|
46
|
+
v2 = cgroup_v2_quota(root, proc_cgroup)
|
|
47
|
+
return [v2, 'cgroup v2 cpu.max'] if v2
|
|
38
48
|
|
|
39
|
-
|
|
49
|
+
[cgroup_v1_quota(root), 'cgroup v1 cpu.cfs_quota_us']
|
|
40
50
|
end
|
|
41
51
|
|
|
42
52
|
def cgroup_v2_quota(root, proc_cgroup)
|
|
@@ -63,7 +73,7 @@ module Wurk
|
|
|
63
73
|
quota, period = read(file)&.split
|
|
64
74
|
return nil if quota.nil? || quota == 'max'
|
|
65
75
|
|
|
66
|
-
|
|
76
|
+
ratio(quota, period)
|
|
67
77
|
end
|
|
68
78
|
|
|
69
79
|
def cgroup_v1_quota(root)
|
|
@@ -73,17 +83,18 @@ module Wurk
|
|
|
73
83
|
|
|
74
84
|
return nil if quota.strip.start_with?('-')
|
|
75
85
|
|
|
76
|
-
return
|
|
86
|
+
return ratio(quota, read(File.join(root, dir, 'cpu.cfs_period_us')))
|
|
77
87
|
end
|
|
78
88
|
nil
|
|
79
89
|
end
|
|
80
90
|
|
|
81
|
-
|
|
91
|
+
# Rational, so rounding up a whole quota never lands one CPU high.
|
|
92
|
+
def ratio(quota, period)
|
|
82
93
|
quota = Integer(quota.to_s.strip, 10)
|
|
83
94
|
period = Integer(period.to_s.strip, 10)
|
|
84
95
|
return nil unless quota.positive? && period.positive?
|
|
85
96
|
|
|
86
|
-
(quota
|
|
97
|
+
Rational(quota, period)
|
|
87
98
|
rescue ArgumentError
|
|
88
99
|
nil
|
|
89
100
|
end
|
|
@@ -15,6 +15,9 @@ module Wurk
|
|
|
15
15
|
class BookkeepingFailed < ::StandardError; end
|
|
16
16
|
|
|
17
17
|
STORE_ERRORS = [RedisClient::Error, ConnectionPool::Error, ConnectionPool::TimeoutError].freeze
|
|
18
|
+
# How a lock script's error is raised, by either copy of sidekiq-unique-jobs.
|
|
19
|
+
# Dragonfly words a refusal at maxmemory as one.
|
|
20
|
+
SCRIPT_ERRORS = %w[Wurk::UniqueJobs::Script::LuaError SidekiqUniqueJobs::Script::LuaError].freeze
|
|
18
21
|
# Past this many owed jobs the oldest is reported and dropped.
|
|
19
22
|
MEMORY = 10_000
|
|
20
23
|
RETRY_EVERY = 1.0
|
|
@@ -30,7 +33,10 @@ module Wurk
|
|
|
30
33
|
@next_try = 0.0
|
|
31
34
|
|
|
32
35
|
class << self
|
|
33
|
-
def store_error?(error)
|
|
36
|
+
def store_error?(error)
|
|
37
|
+
STORE_ERRORS.any? { |klass| error.is_a?(klass) } ||
|
|
38
|
+
(SCRIPT_ERRORS.include?(error.class.name) && UniqueJobsCompat::OOM.match?(error.message))
|
|
39
|
+
end
|
|
34
40
|
|
|
35
41
|
# Reports the failure, tries the owed writes once, keeps what did not land.
|
|
36
42
|
def settle(job, error, pool:, config:)
|
|
@@ -97,12 +103,14 @@ module Wurk
|
|
|
97
103
|
true
|
|
98
104
|
end
|
|
99
105
|
|
|
100
|
-
# Locksmith#unlock only drops a lock this
|
|
106
|
+
# Locksmith#unlock only drops a lock this run holds: the write can land long
|
|
107
|
+
# after the job, when its jid is running again elsewhere. Both digests: an
|
|
101
108
|
# until_and_while_executing job takes its base lock back when an error
|
|
102
109
|
# crosses it, on top of the `:RUN` lock it may still hold.
|
|
103
110
|
def release_unique_locks(job)
|
|
104
111
|
locksmith = UniqueJobsCompat.locksmith_class
|
|
105
|
-
|
|
112
|
+
# A #dup is still this run's payload (UniqueJobs::Run); a #merge need not be.
|
|
113
|
+
digests(job).each { |digest| locksmith.new(job.dup.update('lock_digest' => digest)).unlock }
|
|
106
114
|
end
|
|
107
115
|
|
|
108
116
|
def digests(job)
|
data/lib/wurk/heartbeat.rb
CHANGED
|
@@ -293,12 +293,45 @@ module Wurk
|
|
|
293
293
|
# `info` fields only — Sidekiq Web ignores keys it doesn't know, so the
|
|
294
294
|
# drop-in wire contract holds. Best-effort: nil/0 when the platform has
|
|
295
295
|
# no readable source (the dashboard renders a dash).
|
|
296
|
+
#
|
|
297
|
+
# `cores` and `memory_total_kb` are the machine's, which inside a
|
|
298
|
+
# container is the node's. `cpu_limit` (CPUs, may be fractional) and
|
|
299
|
+
# `memory_limit_kb` are the cgroup's caps, nil when nothing caps tighter
|
|
300
|
+
# than the machine — what the process can actually use. Read once, like
|
|
301
|
+
# the rest: the info JSON is cached per process, and an in-place pod
|
|
302
|
+
# resize shows from the next restart, as it reaches the swarm size.
|
|
296
303
|
def host_facts
|
|
297
|
-
@host_facts ||=
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
304
|
+
@host_facts ||= begin
|
|
305
|
+
total_kb = memory_total_kb
|
|
306
|
+
host_cores = cores
|
|
307
|
+
{
|
|
308
|
+
'cpu_model' => cpu_model,
|
|
309
|
+
'cores' => host_cores,
|
|
310
|
+
'memory_total_kb' => total_kb,
|
|
311
|
+
'cpu_limit' => cpu_limit(host_cores),
|
|
312
|
+
'memory_limit_kb' => memory_limit_kb(total_kb)
|
|
313
|
+
}
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def cpu_limit(host_cores, **cgroup)
|
|
318
|
+
quota = CpuCount.quota(**cgroup)
|
|
319
|
+
return nil if quota.nil? || (host_cores && quota >= host_cores)
|
|
320
|
+
|
|
321
|
+
# 4 places: the smallest quota the kernel takes, 1ms per 1s, is 0.001.
|
|
322
|
+
quota.to_f.round(4)
|
|
323
|
+
rescue StandardError
|
|
324
|
+
nil
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def memory_limit_kb(total_kb, **cgroup)
|
|
328
|
+
bytes = MemoryLimit.detect(**cgroup)
|
|
329
|
+
return nil if bytes.nil?
|
|
330
|
+
|
|
331
|
+
kb = bytes / 1024
|
|
332
|
+
kb if total_kb.to_i <= 0 || kb < total_kb
|
|
333
|
+
rescue StandardError
|
|
334
|
+
nil
|
|
302
335
|
end
|
|
303
336
|
|
|
304
337
|
def cores(etc = Etc)
|
data/lib/wurk/lazy_loader.rb
CHANGED
|
@@ -26,7 +26,7 @@ module Wurk
|
|
|
26
26
|
TOP_LEVEL = {
|
|
27
27
|
# Server tier.
|
|
28
28
|
CLI: 'cli', Embedded: 'embedded', Swarm: 'swarm', Launcher: 'launcher', Manager: 'manager',
|
|
29
|
-
Heartbeat: 'heartbeat', Scheduled: 'scheduled', Leader: 'leader',
|
|
29
|
+
Heartbeat: 'heartbeat', MemoryLimit: 'memory_limit', Scheduled: 'scheduled', Leader: 'leader',
|
|
30
30
|
Cron: 'cron', Periodic: 'cron', History: 'history', Health: 'health', ShutdownGate: 'shutdown_gate',
|
|
31
31
|
Topology: 'topology', RailsBoot: 'rails_boot',
|
|
32
32
|
# On-demand tier.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Wurk only: a run enters the lock its jid already holds (taken at push, or left
|
|
2
|
+
-- by a run that crashed or is still unwinding) and becomes its holder: the value
|
|
3
|
+
-- beside the jid is from now on this run's, so an earlier run of the same jid can
|
|
4
|
+
-- neither unlock nor renew it. Takes nothing: a jid that is not in LOCKED gets 0
|
|
5
|
+
-- and no key is written. Every key is in KEYS.
|
|
6
|
+
-- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
|
|
7
|
+
-- ARGV = [jid, run]
|
|
8
|
+
local locked, job_id, run = KEYS[4], ARGV[1], ARGV[2]
|
|
9
|
+
|
|
10
|
+
if redis.call("HEXISTS", locked, job_id) == 0 then
|
|
11
|
+
return 0
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
redis.call("HSET", locked, job_id, run)
|
|
15
|
+
return 1
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
-- sidekiq-unique-jobs 8.x lock.lua: take the lock once the queued jid was primed
|
|
2
2
|
-- (the blocking path). Every key is in KEYS.
|
|
3
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]
|
|
4
|
+
-- ARGV = [jid, pttl, lock_type, limit, lock_score, now, max_history, script_name, run]
|
|
5
|
+
-- `run` is Wurk's: the token of the run taking the lock (see unique_jobs_claim.lua),
|
|
6
|
+
-- empty when a push takes it. The gem writes `now` in its place.
|
|
5
7
|
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
8
|
local job_id, pttl, lock_type, limit, lock_score = ARGV[1], tonumber(ARGV[2]), ARGV[3], tonumber(ARGV[4]), ARGV[5]
|
|
7
9
|
local now, max_history, script_name = tonumber(ARGV[6]), tonumber(ARGV[7]), ARGV[8]
|
|
10
|
+
local run = ARGV[9] or ""
|
|
8
11
|
|
|
9
12
|
local function log(message, prev_jid)
|
|
10
13
|
if not max_history or max_history == 0 then return end
|
|
@@ -24,6 +27,7 @@ local function drop_queued()
|
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
if redis.call("HEXISTS", locked, job_id) == 1 then
|
|
30
|
+
if #run > 0 then redis.call("HSET", locked, job_id, run) end
|
|
27
31
|
log("Duplicate")
|
|
28
32
|
drop_queued()
|
|
29
33
|
return job_id
|
|
@@ -41,7 +45,7 @@ else
|
|
|
41
45
|
if #lock_score == 0 then score = now end
|
|
42
46
|
redis.call("ZADD", digests, score, digest)
|
|
43
47
|
end
|
|
44
|
-
redis.call("HSET", locked, job_id, now)
|
|
48
|
+
redis.call("HSET", locked, job_id, #run > 0 and run or now)
|
|
45
49
|
drop_queued()
|
|
46
50
|
|
|
47
51
|
if pttl and pttl > 0 then
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
-- Wurk only: sidekiq-unique-jobs 8.x has no refresh. Pushes out the expiry of a
|
|
2
2
|
-- lock this jid still holds, re-applying from now what lock.lua and
|
|
3
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.
|
|
4
|
+
-- not in LOCKED, or is there for a later run of it, gets 0 and no key is written.
|
|
5
|
+
-- Every key is in KEYS.
|
|
5
6
|
-- KEYS = [digest, queued, primed, locked, info, changelog, digests, expiring_digests]
|
|
6
|
-
-- ARGV = [jid, pttl, now]
|
|
7
|
-
--
|
|
7
|
+
-- ARGV = [jid, pttl, now, run]
|
|
8
|
+
-- `run` is the token of the run renewing (see unique_jobs_claim.lua), empty when
|
|
9
|
+
-- the caller is known by jid alone.
|
|
10
|
+
-- Returns 1 when the caller holds the lock, 0 otherwise.
|
|
8
11
|
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])
|
|
12
|
+
local job_id, pttl, now, run = ARGV[1], tonumber(ARGV[2]), tonumber(ARGV[3]), ARGV[4]
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
-- A value that is another run's mark (fifteen decimals, UniqueJobs::Run.token). Any
|
|
15
|
+
-- other value says only that the jid holds the lock: one the gem or an older Wurk
|
|
16
|
+
-- wrote, or a snapshot put back.
|
|
17
|
+
local function another_runs(holder)
|
|
18
|
+
local decimals = string.match(holder, "^%d+%.(%d+)$")
|
|
19
|
+
return #run > 0 and holder ~= run and decimals and #decimals == 15
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
local holder = redis.call("HGET", locked, job_id)
|
|
23
|
+
if not holder or another_runs(holder) then
|
|
12
24
|
return 0
|
|
13
25
|
end
|
|
14
26
|
|
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
-- lock (or the lock was orphaned), nil while another holder keeps it. The "1"
|
|
3
3
|
-- pushed to QUEUED wakes a job blocked on the lock. Every key is in KEYS.
|
|
4
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]
|
|
5
|
+
-- ARGV = [jid, pttl, lock_type, limit, lock_score, now, max_history, script_name, sync_locked, run]
|
|
6
|
+
-- `run` is Wurk's: the token of the run unlocking (see unique_jobs_claim.lua), empty
|
|
7
|
+
-- when the unlock is the jid's. A lock marked by another run of the jid is left whole.
|
|
6
8
|
local digest, queued, primed, locked, info, changelog, digests = KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5], KEYS[6], KEYS[7]
|
|
7
9
|
local job_id, lock_type, limit = ARGV[1], ARGV[3], tonumber(ARGV[4])
|
|
8
10
|
local now, max_history, script_name, sync_locked = tonumber(ARGV[6]), tonumber(ARGV[7]), ARGV[8], ARGV[9] == "1"
|
|
11
|
+
local run = ARGV[10] or ""
|
|
12
|
+
|
|
13
|
+
-- A value that is another run's mark (fifteen decimals, UniqueJobs::Run.token). Any
|
|
14
|
+
-- other value says only that the jid holds the lock: one the gem or an older Wurk
|
|
15
|
+
-- wrote, or a snapshot put back.
|
|
16
|
+
local function another_runs(holder)
|
|
17
|
+
local decimals = string.match(holder, "^%d+%.(%d+)$")
|
|
18
|
+
return #run > 0 and holder ~= run and decimals and #decimals == 15
|
|
19
|
+
end
|
|
9
20
|
|
|
10
21
|
local function log(message, prev_jid)
|
|
11
22
|
if not max_history or max_history == 0 then return end
|
|
@@ -24,10 +35,19 @@ if sync_locked and limit <= 1 then
|
|
|
24
35
|
return job_id
|
|
25
36
|
end
|
|
26
37
|
|
|
27
|
-
local
|
|
38
|
+
local holder = redis.call("HGET", locked, job_id)
|
|
39
|
+
local holds_lock = holder and true or false
|
|
40
|
+
if holder and another_runs(holder) then
|
|
41
|
+
log("Superseded by a later run")
|
|
42
|
+
return nil
|
|
43
|
+
end
|
|
28
44
|
if not holds_lock then
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
-- A run that held the lock left the line when it took it: an entry of its jid
|
|
46
|
+
-- there now is a later run's.
|
|
47
|
+
if #run == 0 then
|
|
48
|
+
redis.call("LREM", queued, -1, job_id)
|
|
49
|
+
redis.call("LREM", primed, -1, job_id)
|
|
50
|
+
end
|
|
31
51
|
local others = redis.call("LLEN", queued) + redis.call("LLEN", primed) + redis.call("HLEN", locked)
|
|
32
52
|
if others > 0 then
|
|
33
53
|
log("Yielding to other lock holders")
|
data/lib/wurk/manager.rb
CHANGED
|
@@ -7,7 +7,7 @@ module Wurk
|
|
|
7
7
|
# One per Capsule. Lives inside each forked child and owns the Processor
|
|
8
8
|
# pool. Replaces dead processors on the fly (replace-on-die), forwards
|
|
9
9
|
# the quiet/stop signals received by the Swarm to its processors, and
|
|
10
|
-
# ensures in-flight UnitsOfWork
|
|
10
|
+
# ensures the in-flight UnitsOfWork of threads it kills are bulk_requeued.
|
|
11
11
|
#
|
|
12
12
|
# Lifecycle:
|
|
13
13
|
# * `start` — spawn each processor thread.
|
|
@@ -77,7 +77,7 @@ module Wurk
|
|
|
77
77
|
|
|
78
78
|
# Graceful shutdown: quiet first, then poll for workers to clear.
|
|
79
79
|
# If the deadline elapses with workers still alive we fall through to
|
|
80
|
-
# hard_shutdown, which
|
|
80
|
+
# hard_shutdown, which kills their threads and bulk_requeues their UoWs.
|
|
81
81
|
def stop(deadline)
|
|
82
82
|
quiet
|
|
83
83
|
# Lifecycle hooks (e.g. :quiet) can be async; give them a tick to settle
|
|
@@ -135,42 +135,107 @@ module Wurk
|
|
|
135
135
|
@shutdown&.call
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
#
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
138
|
+
# How long killed threads may take to unwind before what is left of their jobs
|
|
139
|
+
# is requeued anyway, and how long the process gives the last of them after
|
|
140
|
+
# that. Inside what the Launcher and the Swarm allow a Manager past its
|
|
141
|
+
# deadline (Launcher::TEARDOWN_GRACE, the shortest).
|
|
142
|
+
UNWIND_GRACE = 2
|
|
143
|
+
STRAGGLER_GRACE = 1
|
|
144
|
+
UNWIND_POLL = 0.02
|
|
145
|
+
private_constant :UNWIND_POLL
|
|
146
|
+
|
|
147
|
+
# Reached when the deadline expired with workers still busy: raise
|
|
148
|
+
# Wurk::Shutdown into each, and move every unfinished job from the private list
|
|
149
|
+
# back to the public queue (Reliable#bulk_requeue), where it runs again from the
|
|
150
|
+
# top (Sidekiq's at-least-once contract), as soon as its own thread has ended.
|
|
151
|
+
# What has not ended within UNWIND_GRACE is requeued under its running thread.
|
|
152
|
+
#
|
|
153
|
+
# In that order because a requeued job is running elsewhere within a
|
|
154
|
+
# millisecond, and an unwinding run still has `ensure` blocks to go: it
|
|
155
|
+
# releases limiter slots, saves an iteration cursor, rolls back. A run past its
|
|
156
|
+
# requeue does all that beside the run that replaced it. Waiting costs no job:
|
|
157
|
+
# until the move it sits in the private list, which a SIGKILL leaves for the
|
|
158
|
+
# reaper. A fetcher with no private list has nothing holding the payload
|
|
159
|
+
# meanwhile, so its jobs go back first.
|
|
145
160
|
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
161
|
+
# `job` is read off another thread and before the kill, after which a
|
|
162
|
+
# Processor drops it. One that had finished, or was booking its retry, when the
|
|
163
|
+
# interrupt was sent ACKs it (Processor#cut_short?), and bulk_requeue's guard
|
|
164
|
+
# skips the RPUSH on a miss.
|
|
165
|
+
#
|
|
166
|
+
# Every processor is killed even when a requeue raises (Redis down mid-drain):
|
|
167
|
+
# embedded, the host keeps living after #stop, and those threads would carry
|
|
168
|
+
# on executing jobs over pools the launcher is about to reset. The requeue
|
|
169
|
+
# error still propagates to the caller, which reports it.
|
|
151
170
|
def hard_shutdown
|
|
152
171
|
cleanup = workers_snapshot
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
172
|
+
return if cleanup.empty?
|
|
173
|
+
|
|
174
|
+
units = cleanup.to_h { |worker| [worker, worker.job] }.compact
|
|
175
|
+
if capsule.fetcher.is_a?(Fetcher::Reliable)
|
|
176
|
+
unwind_then_requeue(cleanup, units)
|
|
177
|
+
else
|
|
178
|
+
requeue_then_kill(cleanup, units.values)
|
|
160
179
|
end
|
|
180
|
+
ensure
|
|
181
|
+
# The caller typically `exit`s immediately after we return; give threads
|
|
182
|
+
# that outlived the requeue a brief window to run their `ensure` blocks.
|
|
183
|
+
wait_for_unwind(cleanup, STRAGGLER_GRACE) if cleanup
|
|
161
184
|
end
|
|
162
185
|
|
|
163
186
|
private
|
|
164
187
|
|
|
165
|
-
def
|
|
166
|
-
|
|
188
|
+
def unwind_then_requeue(cleanup, units)
|
|
189
|
+
interrupt(cleanup, units.values)
|
|
190
|
+
requeue_as_they_end(units)
|
|
191
|
+
ensure
|
|
192
|
+
# Also flushes the ACKs of the threads that ended, with nothing left to move.
|
|
193
|
+
capsule.fetcher.bulk_requeue(units.values)
|
|
194
|
+
end
|
|
167
195
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
196
|
+
# Drops from `units` what it has put back. A refused requeue leaves the rest to
|
|
197
|
+
# the caller's, at the end of the wait: one more try, not one every poll.
|
|
198
|
+
def requeue_as_they_end(units)
|
|
199
|
+
deadline = monotonic + UNWIND_GRACE
|
|
200
|
+
until units.empty? || monotonic >= deadline
|
|
201
|
+
ended = units.reject { |worker, _| running?(worker) }
|
|
202
|
+
return wait_for_unwind(units.keys, deadline - monotonic) unless requeued?(ended.values)
|
|
203
|
+
|
|
204
|
+
ended.each_key { |worker| units.delete(worker) }
|
|
205
|
+
sleep UNWIND_POLL
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def requeued?(jobs)
|
|
210
|
+
capsule.fetcher.bulk_requeue(jobs) if jobs.any?
|
|
211
|
+
true
|
|
212
|
+
rescue StandardError => e
|
|
213
|
+
capsule.config.handle_exception(e, { context: 'Error requeueing a job interrupted by shutdown' })
|
|
214
|
+
false
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def requeue_then_kill(cleanup, jobs)
|
|
171
218
|
# `&.` like #quiet: a TERM in the pre-prepare! window (traps install
|
|
172
219
|
# before launcher.run) reaches here with no fetcher built yet.
|
|
173
220
|
capsule.fetcher&.bulk_requeue(jobs)
|
|
221
|
+
ensure
|
|
222
|
+
interrupt(cleanup, jobs)
|
|
223
|
+
wait_for_unwind(cleanup, UNWIND_GRACE)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def interrupt(cleanup, jobs)
|
|
227
|
+
cleanup.each(&:kill)
|
|
228
|
+
logger.warn { "Terminating #{cleanup.size} busy threads" }
|
|
229
|
+
log_interrupted(jobs)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def running?(worker) = worker.thread&.alive?
|
|
233
|
+
def monotonic = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
|
234
|
+
|
|
235
|
+
# Polled rather than joined: a join re-raises what ended the thread.
|
|
236
|
+
def wait_for_unwind(cleanup, seconds)
|
|
237
|
+
deadline = monotonic + seconds
|
|
238
|
+
sleep UNWIND_POLL while cleanup.any? { |worker| running?(worker) } && monotonic < deadline
|
|
174
239
|
end
|
|
175
240
|
|
|
176
241
|
# One WARN per job a deploy cut short, because each one runs again from the
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'cpu_count'
|
|
4
|
+
|
|
5
|
+
module Wurk
|
|
6
|
+
# The memory this process's cgroup may use, in bytes, or nil when nothing
|
|
7
|
+
# caps it. `/proc/meminfo` inside a container reports the node's RAM, so a
|
|
8
|
+
# pod limited to 2 GiB on a 64 GiB node reads 64 GiB there; the Busy page
|
|
9
|
+
# shows RSS against this instead.
|
|
10
|
+
#
|
|
11
|
+
# cgroup v2: `memory.max` (`max` = unlimited) in this process's own cgroup
|
|
12
|
+
# and every ancestor, tightest wins (the same walk as {CpuCount}). cgroup v1:
|
|
13
|
+
# `memory.limit_in_bytes` in the memory controller's mount, where
|
|
14
|
+
# "unlimited" is a page-rounded LONG_MAX; anything at or above
|
|
15
|
+
# {V1_UNLIMITED} counts as no limit, and the caller also drops a limit at or
|
|
16
|
+
# above the host's RAM.
|
|
17
|
+
module MemoryLimit
|
|
18
|
+
V1_UNLIMITED = 2**62
|
|
19
|
+
|
|
20
|
+
module_function
|
|
21
|
+
|
|
22
|
+
def detect(root: CpuCount::ROOT, proc_cgroup: CpuCount::PROC_SELF_CGROUP)
|
|
23
|
+
cgroup_v2(root, proc_cgroup) || cgroup_v1(root)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def cgroup_v2(root, proc_cgroup)
|
|
27
|
+
CpuCount.v2_dirs(root, proc_cgroup).filter_map { |dir| bytes(CpuCount.read(File.join(dir, 'memory.max'))) }.min
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def cgroup_v1(root)
|
|
31
|
+
limit = bytes(CpuCount.read(File.join(root, 'memory', 'memory.limit_in_bytes')))
|
|
32
|
+
limit if limit && limit < V1_UNLIMITED
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def bytes(raw)
|
|
36
|
+
value = Integer(raw.to_s.strip, 10)
|
|
37
|
+
value if value.positive?
|
|
38
|
+
rescue ArgumentError
|
|
39
|
+
nil
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/wurk/metrics/deaths.rb
CHANGED
|
@@ -20,13 +20,16 @@ module Wurk
|
|
|
20
20
|
# fleet does not). #record reports a failed count, which may or may not have
|
|
21
21
|
# landed (a lost reply); the schedule-promote script cannot report, and drops it.
|
|
22
22
|
#
|
|
23
|
-
# Fields are
|
|
24
|
-
#
|
|
23
|
+
# Fields are escaped as Redis's cjson escapes them (CJSON_ESCAPES), so a pair the
|
|
24
|
+
# schedule-promote script counts lands on the same field. json's `script_safe`
|
|
25
|
+
# escaped `/` until 3.2.0.
|
|
25
26
|
module Deaths
|
|
26
27
|
MAX_SERIES = 500
|
|
27
28
|
UNKNOWN = 'unknown'
|
|
28
29
|
OTHER = 'other'
|
|
29
30
|
OVERFLOW = ::JSON.generate([OTHER, OTHER]).freeze
|
|
31
|
+
# What cjson escapes and json does not.
|
|
32
|
+
CJSON_ESCAPES = { '/' => '\\/', "\u007f" => '\u007f' }.freeze
|
|
30
33
|
# Name, help and type of the `/metrics` family (Metrics::Prometheus), whose
|
|
31
34
|
# samples are #samples. Read from shared Redis, so every scrape target
|
|
32
35
|
# reports the same value: aggregate with `max`.
|
|
@@ -49,8 +52,8 @@ module Wurk
|
|
|
49
52
|
def field(payload)
|
|
50
53
|
job = payload.is_a?(::String) ? parse(payload) : payload
|
|
51
54
|
job = {} unless job.is_a?(::Hash)
|
|
52
|
-
::JSON.generate([label(job['queue']) || UNKNOWN, label(job['wrapped']) || label(job['class']) || UNKNOWN]
|
|
53
|
-
|
|
55
|
+
::JSON.generate([label(job['queue']) || UNKNOWN, label(job['wrapped']) || label(job['class']) || UNKNOWN])
|
|
56
|
+
.gsub(%r{[/\u007f]}, CJSON_ESCAPES)
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
# `[[{ 'queue' => q, 'class' => c }, count], …]` from an HGETALL reply
|