sidekiq 7.3.9 → 8.0.8
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/Changes.md +116 -0
- data/README.md +16 -13
- data/bin/sidekiqload +10 -10
- data/bin/webload +69 -0
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +104 -58
- data/lib/sidekiq/api.rb +124 -39
- data/lib/sidekiq/capsule.rb +6 -6
- data/lib/sidekiq/cli.rb +15 -19
- data/lib/sidekiq/client.rb +28 -17
- data/lib/sidekiq/component.rb +42 -3
- data/lib/sidekiq/config.rb +23 -20
- data/lib/sidekiq/embedded.rb +2 -1
- data/lib/sidekiq/iterable_job.rb +1 -0
- data/lib/sidekiq/job/iterable.rb +44 -16
- data/lib/sidekiq/job.rb +2 -2
- data/lib/sidekiq/job_logger.rb +4 -4
- data/lib/sidekiq/job_retry.rb +33 -10
- data/lib/sidekiq/job_util.rb +5 -1
- data/lib/sidekiq/launcher.rb +2 -1
- data/lib/sidekiq/loader.rb +57 -0
- data/lib/sidekiq/logger.rb +25 -69
- data/lib/sidekiq/manager.rb +0 -1
- data/lib/sidekiq/metrics/query.rb +71 -45
- data/lib/sidekiq/metrics/shared.rb +8 -5
- data/lib/sidekiq/metrics/tracking.rb +12 -7
- data/lib/sidekiq/middleware/current_attributes.rb +11 -19
- data/lib/sidekiq/paginator.rb +8 -1
- data/lib/sidekiq/processor.rb +21 -14
- data/lib/sidekiq/profiler.rb +72 -0
- data/lib/sidekiq/rails.rb +46 -67
- data/lib/sidekiq/redis_client_adapter.rb +0 -1
- data/lib/sidekiq/redis_connection.rb +14 -3
- data/lib/sidekiq/testing.rb +3 -3
- data/lib/sidekiq/transaction_aware_client.rb +13 -5
- data/lib/sidekiq/version.rb +2 -2
- data/lib/sidekiq/web/action.rb +146 -83
- data/lib/sidekiq/web/application.rb +353 -332
- data/lib/sidekiq/web/config.rb +120 -0
- data/lib/sidekiq/web/helpers.rb +57 -27
- data/lib/sidekiq/web/router.rb +60 -76
- data/lib/sidekiq/web.rb +51 -156
- data/lib/sidekiq.rb +6 -1
- data/sidekiq.gemspec +6 -6
- data/web/assets/images/logo.png +0 -0
- data/web/assets/images/status.png +0 -0
- data/web/assets/javascripts/application.js +26 -26
- data/web/assets/javascripts/base-charts.js +30 -16
- data/web/assets/javascripts/chartjs-adapter-date-fns.min.js +7 -0
- data/web/assets/javascripts/dashboard.js +1 -1
- data/web/assets/javascripts/metrics.js +16 -34
- data/web/assets/stylesheets/style.css +759 -0
- data/web/locales/ar.yml +1 -0
- data/web/locales/cs.yml +1 -0
- data/web/locales/da.yml +1 -0
- data/web/locales/de.yml +1 -0
- data/web/locales/el.yml +1 -0
- data/web/locales/en.yml +6 -0
- data/web/locales/es.yml +24 -2
- data/web/locales/fa.yml +1 -0
- data/web/locales/fr.yml +1 -0
- data/web/locales/gd.yml +1 -0
- data/web/locales/he.yml +1 -0
- data/web/locales/hi.yml +1 -0
- data/web/locales/it.yml +8 -0
- data/web/locales/ja.yml +1 -0
- data/web/locales/ko.yml +1 -0
- data/web/locales/lt.yml +1 -0
- data/web/locales/nb.yml +1 -0
- data/web/locales/nl.yml +1 -0
- data/web/locales/pl.yml +1 -0
- data/web/locales/{pt-br.yml → pt-BR.yml} +2 -1
- data/web/locales/pt.yml +1 -0
- data/web/locales/ru.yml +1 -0
- data/web/locales/sv.yml +1 -0
- data/web/locales/ta.yml +1 -0
- data/web/locales/tr.yml +1 -0
- data/web/locales/uk.yml +6 -5
- data/web/locales/ur.yml +1 -0
- data/web/locales/vi.yml +1 -0
- data/web/locales/{zh-cn.yml → zh-CN.yml} +85 -73
- data/web/locales/{zh-tw.yml → zh-TW.yml} +2 -1
- data/web/views/_footer.erb +31 -33
- data/web/views/_job_info.erb +91 -89
- data/web/views/_metrics_period_select.erb +13 -10
- data/web/views/_nav.erb +14 -21
- data/web/views/_paging.erb +23 -21
- data/web/views/_poll_link.erb +2 -2
- data/web/views/_summary.erb +16 -16
- data/web/views/busy.erb +124 -122
- data/web/views/dashboard.erb +62 -66
- data/web/views/dead.erb +31 -27
- data/web/views/filtering.erb +3 -3
- data/web/views/layout.erb +13 -29
- data/web/views/metrics.erb +75 -81
- data/web/views/metrics_for_job.erb +45 -46
- data/web/views/morgue.erb +61 -70
- data/web/views/profiles.erb +43 -0
- data/web/views/queue.erb +54 -52
- data/web/views/queues.erb +43 -41
- data/web/views/retries.erb +66 -75
- data/web/views/retry.erb +32 -27
- data/web/views/scheduled.erb +59 -55
- data/web/views/scheduled_job_info.erb +1 -1
- metadata +26 -25
- data/web/assets/stylesheets/application-dark.css +0 -147
- data/web/assets/stylesheets/application-rtl.css +0 -163
- data/web/assets/stylesheets/application.css +0 -759
- data/web/assets/stylesheets/bootstrap-rtl.min.css +0 -9
- data/web/assets/stylesheets/bootstrap.css +0 -5
- data/web/views/_status.erb +0 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3a1e8c90888b4135f21e4dfef66fd9ad9ac8c72ab267599a8452f4bd172234a2
         | 
| 4 | 
            +
              data.tar.gz: fa83e70c818fc3b25441e946c1a093a2d9a5f4515ee2bd88522cbafcb8097973
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0ea8ac9585538723d941af6ce9150933669705cf1e3459dcea8989d073d234c4e233e74314a5a682e3111e1290a69671051e847b5ee97970c1edd08293e14bbc
         | 
| 7 | 
            +
              data.tar.gz: 0b253cd035132f786613fbb97440f5d16f48717aedaa7f50865e0e261ce0fc17b64885bea3cdeb5aabe72258c06ed013891d83655bdcf842fc1a261d1b0aa985
         | 
    
        data/Changes.md
    CHANGED
    
    | @@ -2,10 +2,126 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            [Sidekiq Changes](https://github.com/sidekiq/sidekiq/blob/main/Changes.md) | [Sidekiq Pro Changes](https://github.com/sidekiq/sidekiq/blob/main/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/sidekiq/sidekiq/blob/main/Ent-Changes.md)
         | 
| 4 4 |  | 
| 5 | 
            +
            8.0.8
         | 
| 6 | 
            +
            ----------
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            - Allow an optional global iteration max runtime. After executing for this length of time,
         | 
| 9 | 
            +
              Sidekiq will re-queue the job to continue execution at a later time [#6819, fatkodima]
         | 
| 10 | 
            +
            ```ruby
         | 
| 11 | 
            +
            Sidekiq.configure_server do |cfg|
         | 
| 12 | 
            +
              cfg[:max_iteration_runtime] = 600 # ten minutes
         | 
| 13 | 
            +
            end
         | 
| 14 | 
            +
            ```
         | 
| 15 | 
            +
            - Add `discarded_at` attribute when discarding a job so death handlers can distinguish between
         | 
| 16 | 
            +
              a job which was killed and one that was discarded. [#6820, gstokkink]
         | 
| 17 | 
            +
            - `perform_bulk` now accepts an `:at` array of times to schedule each job at the corresponding time.
         | 
| 18 | 
            +
              `perform_bulk(args: [[1], [2]], at: [Time.now, Time.now + 1])` [#6790, fatkodima]
         | 
| 19 | 
            +
            - `perform_bulk` now accepts a `:spread_interval` value to schedule jobs over
         | 
| 20 | 
            +
              the next N seconds. `perform_bulk(..., spread_interval: 60)` [#6792, fatkodima]
         | 
| 21 | 
            +
            - Fix unintended display of flash messages in the Web UI due to session key collision
         | 
| 22 | 
            +
            - Add support for lazy load hooks [#6825]
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            8.0.7
         | 
| 25 | 
            +
            ----------
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            - The `:discard` option for `sidekiq_retries_exhausted` and `sidekiq_retry_in`
         | 
| 28 | 
            +
              now calls death handlers, otherwise it could break other Sidekiq
         | 
| 29 | 
            +
              functionality. [#6741]
         | 
| 30 | 
            +
            - Provide a Plain log formatter which does not colorize output [#6778]
         | 
| 31 | 
            +
            - Job iteration now exposes `current_object` for easy access within the `around_iteration` callback [#6774]
         | 
| 32 | 
            +
            - Fix JS race condition which could skip confirmation dialogs when Live Polling [#6768]
         | 
| 33 | 
            +
            - Fix edge case which could lose CurrentAttributes [#6767]
         | 
| 34 | 
            +
            - Update UK locale [#6776]
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            8.0.6
         | 
| 37 | 
            +
            ----------
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            - Adjust transactional client to use ActiveRecord 7.2's support for
         | 
| 40 | 
            +
              `after_all_transactions_commit` when available. [#6765, rewritten]
         | 
| 41 | 
            +
            - Fix Rails 7.0 and 7.1 compatibility [#6746, mlarraz]
         | 
| 42 | 
            +
            - Flush metrics at `:exit` [#6764]
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            8.0.5
         | 
| 45 | 
            +
            ----------
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            - Add `stopping?` method to AJ adapter for compatibility with the new AJ::Continuations feature [#6732]
         | 
| 48 | 
            +
            - Further improvements to Rails boot compatibility [#6710]
         | 
| 49 | 
            +
            - Add ability to disable CSRF middleware. SameSite cookies prevent
         | 
| 50 | 
            +
              CSRF in a cleaner manner and are default in most browsers now.
         | 
| 51 | 
            +
              CSRF code will be removed in Sidekiq 9.0. [#6739]
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            8.0.4
         | 
| 54 | 
            +
            ----------
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            - Adjust Rails integration for various edge cases [6713]
         | 
| 57 | 
            +
            - Flush job iteration state when an error is raised [#6704]
         | 
| 58 | 
            +
            - Update Accept-Language parsing in Web UI [#6721]
         | 
| 59 | 
            +
            - Remove fixed-width in Web UI [#6686]
         | 
| 60 | 
            +
            - Adjust CSRF middleware ordering [#6688]
         | 
| 61 | 
            +
            - Support proxies when POSTing profiles to profiler.firefox.com [#6687]
         | 
| 62 | 
            +
            - Dont swallow NoMethodErrors in CurrentAttributes [#6685]
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            8.0.3
         | 
| 65 | 
            +
            ----------
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            - Configure Vernier output directory [#6674]
         | 
| 68 | 
            +
            - Rework Rails integration [#6669]
         | 
| 69 | 
            +
            - Implement flash messages for the Web UI [#6675]
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            8.0.2
         | 
| 72 | 
            +
            ----------
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            - Add `on(:exit)` event to run code right before the Sidekiq process exits [#6637]
         | 
| 75 | 
            +
            - Metrics page crashes with Rack 3.1+ [#6646]
         | 
| 76 | 
            +
             | 
| 77 | 
            +
            8.0.1
         | 
| 78 | 
            +
            ----------
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            - Relax Redis requirement to 7.0 for compatibility with AWS and Ubuntu 24.04 LTS. [#6630]
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            8.0.0
         | 
| 83 | 
            +
            ----------
         | 
| 84 | 
            +
             | 
| 85 | 
            +
            - **WARNING** The underlying class name for Active Jobs has changed from `ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper` to `Sidekiq::ActiveJob::Wrapper`.
         | 
| 86 | 
            +
              The old name will still work in 8.x.
         | 
| 87 | 
            +
            - **WARNING** The `created_at`, `enqueued_at`, `failed_at` and `retried_at` attributes are now stored as epoch milliseconds, rather than epoch floats.
         | 
| 88 | 
            +
              This is meant to avoid precision issues with JSON and JavaScript's 53-bit Floats.
         | 
| 89 | 
            +
              Example: `"created_at" => 1234567890.123456` -> `"created_at" => 1234567890123`.
         | 
| 90 | 
            +
            - **NEW FEATURE** Job Profiling is now supported with [Vernier](https://vernier.prof)
         | 
| 91 | 
            +
              which makes it really easy to performance tune your slow jobs.
         | 
| 92 | 
            +
              The Web UI contains a new **Profiles** tab to view any collected profile data.
         | 
| 93 | 
            +
              Please read the new [Profiling](https://github.com/sidekiq/sidekiq/wiki/Profiling) wiki page for details.
         | 
| 94 | 
            +
            - **NEW FEATURE** Job Metrics now store up to 72 hours of data and the Web UI allows display of 24/48/72 hours. [#6614]
         | 
| 95 | 
            +
            - CurrentAttribute support now uses `ActiveJob::Arguments` to serialize the context object, supporting Symbols and GlobalID.
         | 
| 96 | 
            +
              The change should be backwards compatible. [#6510]
         | 
| 97 | 
            +
            - Freshen up `Sidekiq::Web` to simplify the code and improve security [#6532]
         | 
| 98 | 
            +
              The CSS has been rewritten from scratch to remove the Bootstrap framework.
         | 
| 99 | 
            +
            - Add `on_cancel` callback for iterable jobs [#6607]
         | 
| 100 | 
            +
            - Add `cursor` reader to get the current cursor inside iterable jobs [#6606]
         | 
| 101 | 
            +
            - Default error logging has been modified to use Ruby's `Exception#detailed_message` and `#full_message` APIs.
         | 
| 102 | 
            +
            - CI now runs against Redis, Dragonfly and Valkey.
         | 
| 103 | 
            +
            - Job tags now allow custom CSS display [#6595]
         | 
| 104 | 
            +
            - The Web UI's language picker now shows options in the native language
         | 
| 105 | 
            +
            - Remove global variable usage within the codebase
         | 
| 106 | 
            +
            - Colorize and adjust logging for easier reading
         | 
| 107 | 
            +
            - Adjust Sidekiq's default thread priority to -1 for a 50ms timeslice.
         | 
| 108 | 
            +
              This can help avoid TimeoutErrors when Sidekiq is overloaded. [#6543]
         | 
| 109 | 
            +
            - Use `Logger#with_level`, remove Sidekiq's custom impl
         | 
| 110 | 
            +
            - Remove `base64` gem dependency
         | 
| 111 | 
            +
            - Support: (Dragonfly 1.27+, Valkey 7.2+, Redis 7.2+), Ruby 3.2+, Rails 7.0+
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            7.3.10
         | 
| 114 | 
            +
            ----------
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            - Deprecate Redis :password as a String to avoid log disclosure. [#6625]
         | 
| 117 | 
            +
              Use a Proc instead: `config.redis = { password: ->(username) { "password" } }`
         | 
| 118 | 
            +
             | 
| 5 119 | 
             
            7.3.9
         | 
| 6 120 | 
             
            ----------
         | 
| 7 121 |  | 
| 8 122 | 
             
            - Only require activejob if necessary [#6584]
         | 
| 123 | 
            +
              You might get `uninitialized constant Sidekiq::ActiveJob` if you
         | 
| 124 | 
            +
              `require 'sidekiq'` before `require 'rails'`.
         | 
| 9 125 | 
             
            - Fix iterable job cancellation [#6589]
         | 
| 10 126 | 
             
            - Web UI accessibility improvements [#6604]
         | 
| 11 127 |  | 
    
        data/README.md
    CHANGED
    
    | @@ -4,21 +4,23 @@ Sidekiq | |
| 4 4 | 
             
            [](https://rubygems.org/gems/sidekiq)
         | 
| 5 5 | 
             
            
         | 
| 6 6 |  | 
| 7 | 
            -
            Simple, efficient background  | 
| 7 | 
            +
            Simple, efficient background jobs for Ruby.
         | 
| 8 8 |  | 
| 9 9 | 
             
            Sidekiq uses threads to handle many jobs at the same time in the
         | 
| 10 | 
            -
            same process. | 
| 11 | 
            -
            Rails to make background processing dead simple.
         | 
| 10 | 
            +
            same process. Sidekiq can be used by any Ruby application.
         | 
| 12 11 |  | 
| 13 12 |  | 
| 14 13 | 
             
            Requirements
         | 
| 15 14 | 
             
            -----------------
         | 
| 16 15 |  | 
| 17 | 
            -
            - Redis: Redis  | 
| 18 | 
            -
            - Ruby: MRI 2 | 
| 16 | 
            +
            - Redis: Redis 7.0+, Valkey 7.2+ or Dragonfly 1.27+
         | 
| 17 | 
            +
            - Ruby: MRI 3.2+ or JRuby 9.4+.
         | 
| 19 18 |  | 
| 20 | 
            -
            Sidekiq  | 
| 21 | 
            -
             | 
| 19 | 
            +
            Sidekiq 8.0 supports Rails and Active Job 7.0+.
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Sidekiq supports [Valkey](https://valkey.io) and [Dragonfly](https://www.dragonflydb.io) as Redis alternatives.
         | 
| 22 | 
            +
            Redis 7.2.4 is considered to be the canonical implementation.
         | 
| 23 | 
            +
            Incompatibilities with that version are considered bugs.
         | 
| 22 24 |  | 
| 23 25 | 
             
            Installation
         | 
| 24 26 | 
             
            -----------------
         | 
| @@ -42,6 +44,7 @@ The benchmark in `bin/sidekiqload` creates 500,000 no-op jobs and drains them as | |
| 42 44 | 
             
            This requires a lot of Redis network I/O and JSON parsing.
         | 
| 43 45 | 
             
            This benchmark is IO-bound so we increase the concurrency to 25.
         | 
| 44 46 | 
             
            If your application is sending lots of emails or performing other network-intensive work, you could see a similar benefit but be careful not to saturate the CPU.
         | 
| 47 | 
            +
            Real world applications will rarely if ever need to use concurrency greater than 10.
         | 
| 45 48 |  | 
| 46 49 | 
             
            Version | Time to process 500k jobs | Throughput (jobs/sec) | Ruby | Concurrency | Job Type
         | 
| 47 50 | 
             
            -----------------|------|---------|---------|------------------------|---
         | 
| @@ -62,7 +65,7 @@ Want to Upgrade? | |
| 62 65 | 
             
            Use `bundle up sidekiq` to upgrade Sidekiq and all its dependencies.
         | 
| 63 66 | 
             
            Upgrade notes between each major version can be found in the `docs/` directory.
         | 
| 64 67 |  | 
| 65 | 
            -
            I also sell Sidekiq Pro and Sidekiq Enterprise, extensions to Sidekiq which provide more
         | 
| 68 | 
            +
            I also sell [Sidekiq Pro](https://billing.contribsys.com/spro/) and [Sidekiq Enterprise](https://billing.contribsys.com/sent/new.cgi), extensions to Sidekiq which provide more
         | 
| 66 69 | 
             
            features, a commercial-friendly license and allow you to support high
         | 
| 67 70 | 
             
            quality open source development all at the same time.  Please see the
         | 
| 68 71 | 
             
            [Sidekiq](https://sidekiq.org/) homepage for more detail.
         | 
| @@ -71,7 +74,7 @@ quality open source development all at the same time.  Please see the | |
| 71 74 | 
             
            Problems?
         | 
| 72 75 | 
             
            -----------------
         | 
| 73 76 |  | 
| 74 | 
            -
            ** | 
| 77 | 
            +
            **Do not directly email any Sidekiq committers with questions or problems.**
         | 
| 75 78 | 
             
            A community is best served when discussions are held in public.
         | 
| 76 79 |  | 
| 77 80 | 
             
            If you have a problem, please review the [FAQ](https://github.com/sidekiq/sidekiq/wiki/FAQ) and [Troubleshooting](https://github.com/sidekiq/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages.
         | 
| @@ -86,21 +89,21 @@ Useful resources: | |
| 86 89 | 
             
            * Occasional announcements are made to the [@sidekiq](https://ruby.social/@sidekiq) Mastodon account.
         | 
| 87 90 | 
             
            * The [Sidekiq tag](https://stackoverflow.com/questions/tagged/sidekiq) on Stack Overflow has lots of useful Q & A.
         | 
| 88 91 |  | 
| 89 | 
            -
            Every Thursday morning is Sidekiq  | 
| 92 | 
            +
            Every Thursday morning is Sidekiq Office Hour: I video chat and answer questions.
         | 
| 90 93 | 
             
            See the [Sidekiq support page](https://sidekiq.org/support.html) for details.
         | 
| 91 94 |  | 
| 92 95 | 
             
            Contributing
         | 
| 93 96 | 
             
            -----------------
         | 
| 94 97 |  | 
| 95 | 
            -
             | 
| 98 | 
            +
            See [the contributing guidelines](https://github.com/sidekiq/sidekiq/blob/main/.github/contributing.md).
         | 
| 96 99 |  | 
| 97 100 | 
             
            License
         | 
| 98 101 | 
             
            -----------------
         | 
| 99 102 |  | 
| 100 | 
            -
             | 
| 103 | 
            +
            See [LICENSE.txt](https://github.com/sidekiq/sidekiq/blob/main/LICENSE.txt) for licensing details.
         | 
| 101 104 | 
             
            The license for Sidekiq Pro and Sidekiq Enterprise can be found in [COMM-LICENSE.txt](https://github.com/sidekiq/sidekiq/blob/main/COMM-LICENSE.txt).
         | 
| 102 105 |  | 
| 103 106 | 
             
            Author
         | 
| 104 107 | 
             
            -----------------
         | 
| 105 108 |  | 
| 106 | 
            -
            Mike Perham, [ | 
| 109 | 
            +
            Mike Perham, [mastodon](https://ruby.social/@getajobmike), [https://www.mikeperham.com](https://www.mikeperham.com) / [https://www.contribsys.com](https://www.contribsys.com)
         | 
    
        data/bin/sidekiqload
    CHANGED
    
    | @@ -28,7 +28,7 @@ require "ruby-prof" if ENV["PROFILE"] | |
| 28 28 | 
             
            require "bundler/setup"
         | 
| 29 29 | 
             
            Bundler.require(:default, :load_test)
         | 
| 30 30 |  | 
| 31 | 
            -
            latency = Integer(ENV["LATENCY"] ||  | 
| 31 | 
            +
            latency = Integer(ENV["LATENCY"] || 0)
         | 
| 32 32 | 
             
            if latency > 0
         | 
| 33 33 | 
             
              # brew tap shopify/shopify
         | 
| 34 34 | 
             
              # brew install toxiproxy
         | 
| @@ -86,7 +86,7 @@ class Loader | |
| 86 86 | 
             
              def initialize
         | 
| 87 87 | 
             
                @iter = ENV["GC"] ? 10 : 500
         | 
| 88 88 | 
             
                @count = Integer(ENV["COUNT"] || 1_000)
         | 
| 89 | 
            -
                @latency = Integer(ENV["LATENCY"] ||  | 
| 89 | 
            +
                @latency = Integer(ENV["LATENCY"] || 0)
         | 
| 90 90 | 
             
              end
         | 
| 91 91 |  | 
| 92 92 | 
             
              def configure
         | 
| @@ -137,7 +137,7 @@ class Loader | |
| 137 137 | 
             
              end
         | 
| 138 138 |  | 
| 139 139 | 
             
              def setup
         | 
| 140 | 
            -
                Sidekiq.logger. | 
| 140 | 
            +
                Sidekiq.logger.warn("Setup RSS: #{Process.rss}")
         | 
| 141 141 | 
             
                Sidekiq.redis { |c| c.flushdb }
         | 
| 142 142 | 
             
                start = Time.now
         | 
| 143 143 | 
             
                if ENV["AJ"]
         | 
| @@ -167,9 +167,9 @@ class Loader | |
| 167 167 | 
             
                    if total == 0
         | 
| 168 168 | 
             
                      ending = Time.now - @start
         | 
| 169 169 | 
             
                      size = @iter * @count
         | 
| 170 | 
            -
                      Sidekiq.logger. | 
| 171 | 
            -
                      Sidekiq.logger. | 
| 172 | 
            -
                      Sidekiq.logger. | 
| 170 | 
            +
                      Sidekiq.logger.warn("Done, #{size} jobs in #{ending} sec, #{(size / ending).to_i} jobs/sec")
         | 
| 171 | 
            +
                      Sidekiq.logger.warn("Ending RSS: #{Process.rss}")
         | 
| 172 | 
            +
                      Sidekiq.logger.warn("Now here's the latency for three jobs")
         | 
| 173 173 |  | 
| 174 174 | 
             
                      if ENV["AJ"]
         | 
| 175 175 | 
             
                        LoadJob.perform_later("", 1, {}, Time.now.to_f)
         | 
| @@ -191,7 +191,7 @@ class Loader | |
| 191 191 | 
             
              end
         | 
| 192 192 |  | 
| 193 193 | 
             
              def with_latency(latency, &block)
         | 
| 194 | 
            -
                Sidekiq.logger. | 
| 194 | 
            +
                Sidekiq.logger.warn "Simulating #{latency}ms of latency between Sidekiq and redis"
         | 
| 195 195 | 
             
                if latency > 0
         | 
| 196 196 | 
             
                  Toxiproxy[:redis].downstream(:latency, latency: latency).apply(&block)
         | 
| 197 197 | 
             
                else
         | 
| @@ -204,8 +204,8 @@ class Loader | |
| 204 204 | 
             
                monitor
         | 
| 205 205 |  | 
| 206 206 | 
             
                if ENV["PROFILE"]
         | 
| 207 | 
            -
                  RubyProf.exclude_threads  | 
| 208 | 
            -
                   | 
| 207 | 
            +
                  $profile = RubyProf::Profile.new(exclude_threads: [@monitor])
         | 
| 208 | 
            +
                  $profile.start
         | 
| 209 209 | 
             
                elsif ENV["GC"]
         | 
| 210 210 | 
             
                  GC.start
         | 
| 211 211 | 
             
                  GC.compact
         | 
| @@ -236,7 +236,7 @@ class Loader | |
| 236 236 | 
             
                Sidekiq.logger.error("GC End RSS: #{Process.rss}") if ENV["GC"]
         | 
| 237 237 | 
             
                if ENV["PROFILE"]
         | 
| 238 238 | 
             
                  Sidekiq.logger.error("Profiling...")
         | 
| 239 | 
            -
                  result =  | 
| 239 | 
            +
                  result = $profile.stop
         | 
| 240 240 | 
             
                  printer = RubyProf::GraphHtmlPrinter.new(result)
         | 
| 241 241 | 
             
                  printer.print(File.new("output.html", "w"), min_percent: 1)
         | 
| 242 242 | 
             
                end
         | 
    
        data/bin/webload
    ADDED
    
    | @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'bundler'
         | 
| 4 | 
            +
            Bundler.setup
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # This skeleton allows you to run Sidekiq::Web page rendering
         | 
| 7 | 
            +
            # through Vernier for tuning.
         | 
| 8 | 
            +
            require "sidekiq/web"
         | 
| 9 | 
            +
            require "rack/test"
         | 
| 10 | 
            +
            require "vernier"
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            Sidekiq::Web.configure do |config|
         | 
| 13 | 
            +
              config.middlewares.clear # remove csrf
         | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            class SomeJob
         | 
| 17 | 
            +
              include Sidekiq::Job
         | 
| 18 | 
            +
            end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            class BenchWeb
         | 
| 21 | 
            +
              include Rack::Test::Methods
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def app
         | 
| 24 | 
            +
                Sidekiq::Web.new
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              def warmup(page = "/scheduled")
         | 
| 28 | 
            +
                # Sidekiq.redis {|c| c.flushdb }
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                # 100.times do |idx|
         | 
| 31 | 
            +
                #   SomeJob.perform_at(idx, 1, 3, "mike", {"foo" => "bar"})
         | 
| 32 | 
            +
                # end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                100.times do
         | 
| 35 | 
            +
                  get page
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              def load(page = "/scheduled", count = 10_000)
         | 
| 40 | 
            +
                profile do
         | 
| 41 | 
            +
                  count.times do
         | 
| 42 | 
            +
                    get page
         | 
| 43 | 
            +
                    raise last_response.inspect unless last_response.status == 200
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              def profile(&)
         | 
| 49 | 
            +
                if ENV["PROF"]
         | 
| 50 | 
            +
                  Vernier.profile(out: "profile.json.gz", &)
         | 
| 51 | 
            +
                else
         | 
| 52 | 
            +
                  yield
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
            end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            def timer(name="block", count = 10_000)
         | 
| 58 | 
            +
              a = Time.now
         | 
| 59 | 
            +
              yield count
         | 
| 60 | 
            +
              b = Time.now
         | 
| 61 | 
            +
              puts "#{name} in #{b - a} sec"
         | 
| 62 | 
            +
            end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            page = "/busy"
         | 
| 65 | 
            +
            b = BenchWeb.new
         | 
| 66 | 
            +
            b.warmup(page)
         | 
| 67 | 
            +
            timer(page) do |count|
         | 
| 68 | 
            +
              b.load(page, count)
         | 
| 69 | 
            +
            end
         | 
| @@ -1,75 +1,121 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
                remove_const(:SidekiqAdapter) if const_defined?(:SidekiqAdapter)
         | 
| 3 | 
            +
            begin
         | 
| 4 | 
            +
              gem "activejob", ">= 7.0"
         | 
| 5 | 
            +
              require "active_job"
         | 
| 7 6 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
                 | 
| 10 | 
            -
                # To use Sidekiq set the queue_adapter config to +:sidekiq+.
         | 
| 11 | 
            -
                #
         | 
| 12 | 
            -
                #   Rails.application.config.active_job.queue_adapter = :sidekiq
         | 
| 13 | 
            -
                class SidekiqAdapter
         | 
| 14 | 
            -
                  # Defines whether enqueuing should happen implicitly to after commit when called
         | 
| 15 | 
            -
                  # from inside a transaction.
         | 
| 7 | 
            +
              module Sidekiq
         | 
| 8 | 
            +
                module ActiveJob
         | 
| 16 9 | 
             
                  # @api private
         | 
| 17 | 
            -
                   | 
| 18 | 
            -
                     | 
| 19 | 
            -
                  end
         | 
| 10 | 
            +
                  class Wrapper
         | 
| 11 | 
            +
                    include Sidekiq::Job
         | 
| 20 12 |  | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
                     | 
| 24 | 
            -
                      wrapped: job.class,
         | 
| 25 | 
            -
                      queue: job.queue_name
         | 
| 26 | 
            -
                    ).perform_async(job.serialize)
         | 
| 13 | 
            +
                    def perform(job_data)
         | 
| 14 | 
            +
                      ::ActiveJob::Base.execute(job_data.merge("provider_job_id" => jid))
         | 
| 15 | 
            +
                    end
         | 
| 27 16 | 
             
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 28 19 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 20 | 
            +
              ActiveSupport.on_load(:active_job) do
         | 
| 21 | 
            +
                # By including the Options module, we allow AJs to directly control sidekiq features
         | 
| 22 | 
            +
                # via the *sidekiq_options* class method and, for instance, not use AJ's retry system.
         | 
| 23 | 
            +
                # AJ retries don't show up in the Sidekiq UI Retries tab, don't save any error data, can't be
         | 
| 24 | 
            +
                # manually retried, don't automatically die, etc.
         | 
| 25 | 
            +
                #
         | 
| 26 | 
            +
                #   class SomeJob < ActiveJob::Base
         | 
| 27 | 
            +
                #     queue_as :default
         | 
| 28 | 
            +
                #     sidekiq_options retry: 3, backtrace: 10
         | 
| 29 | 
            +
                #     def perform
         | 
| 30 | 
            +
                #     end
         | 
| 31 | 
            +
                #   end
         | 
| 32 | 
            +
                include Sidekiq::Job::Options unless respond_to?(:sidekiq_options)
         | 
| 33 | 
            +
              end
         | 
| 36 34 |  | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
                          enqueued_count += jids.compact.size
         | 
| 52 | 
            -
                        end
         | 
| 35 | 
            +
              # Patch the ActiveJob module
         | 
| 36 | 
            +
              module ActiveJob
         | 
| 37 | 
            +
                module QueueAdapters
         | 
| 38 | 
            +
                  # Explicitly remove the implementation existing in older Rails.
         | 
| 39 | 
            +
                  remove_const(:SidekiqAdapter) if const_defined?(:SidekiqAdapter)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  # Sidekiq adapter for Active Job
         | 
| 42 | 
            +
                  #
         | 
| 43 | 
            +
                  # To use Sidekiq set the queue_adapter config to +:sidekiq+.
         | 
| 44 | 
            +
                  #
         | 
| 45 | 
            +
                  #   Rails.application.config.active_job.queue_adapter = :sidekiq
         | 
| 46 | 
            +
                  parent = const_defined?(:AbstractAdapter) ? AbstractAdapter : Object
         | 
| 47 | 
            +
                  class SidekiqAdapter < parent
         | 
| 48 | 
            +
                    @@stopping = false
         | 
| 53 49 |  | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 50 | 
            +
                    callback = -> { @@stopping = true }
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    Sidekiq.configure_client { |config| config.on(:quiet, &callback) }
         | 
| 53 | 
            +
                    Sidekiq.configure_server { |config| config.on(:quiet, &callback) }
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    # Defines whether enqueuing should happen implicitly to after commit when called
         | 
| 56 | 
            +
                    # from inside a transaction.
         | 
| 57 | 
            +
                    # @api private
         | 
| 58 | 
            +
                    def enqueue_after_transaction_commit?
         | 
| 59 | 
            +
                      true
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    # @api private
         | 
| 63 | 
            +
                    def enqueue(job)
         | 
| 64 | 
            +
                      job.provider_job_id = Sidekiq::ActiveJob::Wrapper.set(
         | 
| 65 | 
            +
                        wrapped: job.class,
         | 
| 66 | 
            +
                        queue: job.queue_name
         | 
| 67 | 
            +
                      ).perform_async(job.serialize)
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    # @api private
         | 
| 71 | 
            +
                    def enqueue_at(job, timestamp)
         | 
| 72 | 
            +
                      job.provider_job_id = Sidekiq::ActiveJob::Wrapper.set(
         | 
| 73 | 
            +
                        wrapped: job.class,
         | 
| 74 | 
            +
                        queue: job.queue_name
         | 
| 75 | 
            +
                      ).perform_at(timestamp, job.serialize)
         | 
| 76 | 
            +
                    end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                    # @api private
         | 
| 79 | 
            +
                    def enqueue_all(jobs)
         | 
| 80 | 
            +
                      enqueued_count = 0
         | 
| 81 | 
            +
                      jobs.group_by(&:class).each do |job_class, same_class_jobs|
         | 
| 82 | 
            +
                        same_class_jobs.group_by(&:queue_name).each do |queue, same_class_and_queue_jobs|
         | 
| 83 | 
            +
                          immediate_jobs, scheduled_jobs = same_class_and_queue_jobs.partition { |job| job.scheduled_at.nil? }
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                          if immediate_jobs.any?
         | 
| 86 | 
            +
                            jids = Sidekiq::Client.push_bulk(
         | 
| 87 | 
            +
                              "class" => Sidekiq::ActiveJob::Wrapper,
         | 
| 88 | 
            +
                              "wrapped" => job_class,
         | 
| 89 | 
            +
                              "queue" => queue,
         | 
| 90 | 
            +
                              "args" => immediate_jobs.map { |job| [job.serialize] }
         | 
| 91 | 
            +
                            )
         | 
| 92 | 
            +
                            enqueued_count += jids.compact.size
         | 
| 93 | 
            +
                          end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                          if scheduled_jobs.any?
         | 
| 96 | 
            +
                            jids = Sidekiq::Client.push_bulk(
         | 
| 97 | 
            +
                              "class" => Sidekiq::ActiveJob::Wrapper,
         | 
| 98 | 
            +
                              "wrapped" => job_class,
         | 
| 99 | 
            +
                              "queue" => queue,
         | 
| 100 | 
            +
                              "args" => scheduled_jobs.map { |job| [job.serialize] },
         | 
| 101 | 
            +
                              "at" => scheduled_jobs.map { |job| job.scheduled_at&.to_f }
         | 
| 102 | 
            +
                            )
         | 
| 103 | 
            +
                            enqueued_count += jids.compact.size
         | 
| 104 | 
            +
                          end
         | 
| 63 105 | 
             
                        end
         | 
| 64 106 | 
             
                      end
         | 
| 107 | 
            +
                      enqueued_count
         | 
| 65 108 | 
             
                    end
         | 
| 66 | 
            -
                    enqueued_count
         | 
| 67 | 
            -
                  end
         | 
| 68 109 |  | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 110 | 
            +
                    # @api private
         | 
| 111 | 
            +
                    def stopping? = !!@@stopping
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                    # Defines a class alias for backwards compatibility with enqueued Active Job jobs.
         | 
| 114 | 
            +
                    # @api private
         | 
| 115 | 
            +
                    JobWrapper = Sidekiq::ActiveJob::Wrapper
         | 
| 72 116 | 
             
                  end
         | 
| 73 117 | 
             
                end
         | 
| 74 118 | 
             
              end
         | 
| 119 | 
            +
            rescue Gem::LoadError
         | 
| 120 | 
            +
              # ActiveJob not available or version requirement not met
         | 
| 75 121 | 
             
            end
         |