sidekiq 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq might be problematic. Click here for more details.

Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +4 -0
  3. data/.travis.yml +3 -6
  4. data/4.0-Upgrade.md +3 -0
  5. data/COMM-LICENSE +1 -1
  6. data/Changes.md +69 -0
  7. data/Ent-Changes.md +40 -0
  8. data/Gemfile +6 -5
  9. data/Pro-3.0-Upgrade.md +5 -7
  10. data/Pro-Changes.md +66 -0
  11. data/README.md +2 -1
  12. data/bin/sidekiqload +2 -2
  13. data/lib/sidekiq.rb +5 -1
  14. data/lib/sidekiq/api.rb +3 -1
  15. data/lib/sidekiq/cli.rb +15 -2
  16. data/lib/sidekiq/client.rb +11 -3
  17. data/lib/sidekiq/core_ext.rb +1 -0
  18. data/lib/sidekiq/exception_handler.rb +2 -1
  19. data/lib/sidekiq/extensions/action_mailer.rb +1 -0
  20. data/lib/sidekiq/extensions/active_record.rb +1 -0
  21. data/lib/sidekiq/extensions/class_methods.rb +1 -0
  22. data/lib/sidekiq/extensions/generic_proxy.rb +1 -0
  23. data/lib/sidekiq/fetch.rb +1 -0
  24. data/lib/sidekiq/launcher.rb +9 -3
  25. data/lib/sidekiq/logging.rb +2 -1
  26. data/lib/sidekiq/manager.rb +2 -0
  27. data/lib/sidekiq/middleware/chain.rb +1 -0
  28. data/lib/sidekiq/middleware/i18n.rb +1 -0
  29. data/lib/sidekiq/middleware/server/retry_jobs.rb +7 -7
  30. data/lib/sidekiq/paginator.rb +1 -0
  31. data/lib/sidekiq/processor.rb +29 -25
  32. data/lib/sidekiq/rails.rb +18 -0
  33. data/lib/sidekiq/redis_connection.rb +6 -3
  34. data/lib/sidekiq/scheduled.rb +2 -0
  35. data/lib/sidekiq/testing.rb +1 -0
  36. data/lib/sidekiq/testing/inline.rb +1 -0
  37. data/lib/sidekiq/util.rb +1 -0
  38. data/lib/sidekiq/version.rb +2 -1
  39. data/lib/sidekiq/web.rb +80 -202
  40. data/lib/sidekiq/web/action.rb +99 -0
  41. data/lib/sidekiq/web/application.rb +335 -0
  42. data/lib/sidekiq/{web_helpers.rb → web/helpers.rb} +31 -11
  43. data/lib/sidekiq/web/router.rb +96 -0
  44. data/lib/sidekiq/worker.rb +1 -0
  45. data/sidekiq.gemspec +2 -2
  46. data/test/fake_env.rb +1 -0
  47. data/test/helper.rb +1 -0
  48. data/test/test_actors.rb +1 -0
  49. data/test/test_api.rb +1 -0
  50. data/test/test_cli.rb +15 -2
  51. data/test/test_client.rb +34 -0
  52. data/test/test_exception_handler.rb +2 -1
  53. data/test/test_extensions.rb +1 -0
  54. data/test/test_fetch.rb +1 -0
  55. data/test/test_launcher.rb +17 -2
  56. data/test/test_logging.rb +1 -0
  57. data/test/test_manager.rb +1 -0
  58. data/test/test_middleware.rb +1 -0
  59. data/test/test_processor.rb +1 -0
  60. data/test/test_rails.rb +1 -0
  61. data/test/test_redis_connection.rb +7 -1
  62. data/test/test_retry.rb +1 -0
  63. data/test/test_scheduled.rb +1 -0
  64. data/test/test_scheduling.rb +1 -0
  65. data/test/test_sidekiq.rb +1 -0
  66. data/test/test_testing.rb +1 -0
  67. data/test/test_testing_fake.rb +1 -0
  68. data/test/test_testing_inline.rb +2 -1
  69. data/test/test_util.rb +1 -0
  70. data/test/test_web.rb +53 -5
  71. data/test/test_web_helpers.rb +1 -0
  72. data/web/assets/images/{status-sd8051fd480.png → status.png} +0 -0
  73. data/web/assets/javascripts/application.js +5 -0
  74. data/web/assets/javascripts/locales/{jquery.timeago.no.js → jquery.timeago.nb.js} +1 -1
  75. data/web/assets/stylesheets/application.css +26 -1
  76. data/web/assets/stylesheets/bootstrap.css +4 -8
  77. data/web/locales/de.yml +1 -1
  78. data/web/locales/en.yml +1 -0
  79. data/web/locales/ru.yml +3 -0
  80. data/web/views/_footer.erb +1 -1
  81. data/web/views/_nav.erb +1 -1
  82. data/web/views/busy.erb +4 -4
  83. data/web/views/dashboard.erb +2 -2
  84. data/web/views/dead.erb +1 -1
  85. data/web/views/layout.erb +3 -3
  86. data/web/views/morgue.erb +2 -2
  87. data/web/views/queue.erb +3 -3
  88. data/web/views/queues.erb +1 -1
  89. data/web/views/retries.erb +2 -2
  90. data/web/views/retry.erb +1 -1
  91. data/web/views/scheduled.erb +2 -2
  92. data/web/views/scheduled_job_info.erb +1 -1
  93. metadata +17 -29
  94. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  95. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  96. data/web/assets/images/status/active.png +0 -0
  97. data/web/assets/images/status/idle.png +0 -0
  98. data/web/views/_poll_js.erb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3831fb91606790c4912c4fb8d96a560e49aa9b5
4
- data.tar.gz: 74e50d973aab4a58f00f7176ea640dd52f37e218
3
+ metadata.gz: db0f25c2fe7ea87588364c3eb86e3b929197139c
4
+ data.tar.gz: 8fa8c056e6c5fad50ce5d49838515aca61573458
5
5
  SHA512:
6
- metadata.gz: b5b098a51e90fff82508ddfa1b565d1e06758e99de904870795919314987439231aeeb1b315212eed9dcc771a9464909fa437e6990b799e8c245c52506b66eee
7
- data.tar.gz: e1a1ae8f6c3217333b69187041ac8e1c974ebc29aa862b9abab284ae312d8680d960191defb1e67d7a3e6ee95c9d9a924cfc308f5e96e06a38157e0e0dd45ebe
6
+ metadata.gz: 4a801ac5f3d70ca6e1856cb7369f557d5bb8d1c579e775f6a4f5ed97d534af2d289f884979de978f3a7cab2d1261fabeef6b7fc9e73b1684c7b1daabbd25e0e7
7
+ data.tar.gz: 37c617e0ea241fe8cea7c85e6479e2259e06f1b5bfb06ce811b2529d73adc8a09a67655dbdcaff028ba4cd3226169a79f636f813f7848d7fe8eaa084ea9d5739
@@ -0,0 +1,4 @@
1
+ Ruby version:
2
+ Sidekiq / Pro / Enterprise version(s):
3
+
4
+ If relevant, please include your initializer and any error message with the full backtrace.
data/.travis.yml CHANGED
@@ -3,13 +3,10 @@ sudo: false
3
3
  cache: bundler
4
4
  services:
5
5
  - redis-server
6
+ before_install:
7
+ - gem install bundler
8
+ - gem update bundler
6
9
  rvm:
7
- - 2.0.0
8
- - 2.1.8
9
10
  - 2.2.4
10
11
  - 2.3.0
11
12
  - jruby-head
12
- - rbx-2
13
- matrix:
14
- allow_failures:
15
- - rvm: rbx-2
data/4.0-Upgrade.md CHANGED
@@ -25,6 +25,9 @@ gem 'redis-namespace'
25
25
  `concurrency + 2` connections in your pool or Sidekiq will exit.
26
26
  When in doubt, let Sidekiq size the connection pool for you.
27
27
 
28
+ * Worker data is no longer updated in real-time but rather upon every
29
+ heartbeat. Don't expect the `Sidekiq::Workers` API to be millisecond-precise.
30
+
28
31
  * There's a new testing API based off the `Sidekiq::Queues` namespace. All
29
32
  assertions made against the Worker class still work as expected.
30
33
  ```ruby
data/COMM-LICENSE CHANGED
@@ -28,7 +28,7 @@ In order to use the Software under this Agreement, you must receive a “Source
28
28
 
29
29
  3.1 You shall not (and shall not allow any third party to): (a) decompile, disassemble, or otherwise reverse engineer the Software or attempt to reconstruct or discover any source code, underlying ideas, algorithms, file formats or programming interfaces of the Software by any means whatsoever (except and only to the extent that applicable law prohibits or restricts reverse engineering restrictions); (b) distribute, sell, sublicense, rent, lease or use the Software for time sharing, hosting, service provider or like purposes, except as expressly permitted under this Agreement; (c) redistribute the Software or Modifications other than by including the Software or a portion thereof within your own product, which must have substantially different functionality than the Software or Modifications and must not allow any third party to use the Software or Modifications, or any portions thereof, for software development or application development purposes; (d) redistribute the Software as part of a product, "appliance" or "virtual server"; (e) redistribute the Software on any server which is not directly under your control; (f) remove any product identification, proprietary, copyright or other notices contained in the Software; (g) modify any part of the Software, create a derivative work of any part of the Software (except as permitted in Section 4), or incorporate the Software, except to the extent expressly authorized in writing by Contributed Systems; (h) publicly disseminate performance information or analysis (including, without limitation, benchmarks) from any source relating to the Software; (i) utilize any equipment, device, software, or other means designed to circumvent or remove any form of Source URL or copy protection used by Contributed Systems in connection with the Software, or use the Software together with any authorization code, Source URL, serial number, or other copy protection device not supplied by Contributed Systems; (j) use the Software to develop a product which is competitive with any Contributed Systems product offerings; or (k) use unauthorized Source URLS or keycode(s) or distribute or publish Source URLs or keycode(s), except as may be expressly permitted by Contributed Systems in writing. If your unique Source URL is ever published, Contributed Systems reserves the right to terminate your access without notice.
30
30
 
31
- 3.2 UNDER NO CIRCUMSTANCES MAY YOU USE THE SOFTWARE FOR A PRODUCT THAT IS INTENDED FOR SOFTWARE OR APPLICATION DEVELOPMENT PURPOSES.
31
+ 3.2 UNDER NO CIRCUMSTANCES MAY YOU USE THE SOFTWARE AS PART OF A PRODUCT OR SERVICE THAT PROVIDES SIMILAR FUNCTIONALITY TO THE SOFTWARE ITSELF.
32
32
 
33
33
  The Open Source version of the Software (“LGPL Version”) is licensed
34
34
  under the terms of the GNU Lesser General Public License versions 3.0
data/Changes.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Sidekiq Changes
2
2
 
3
+ 4.2.0
4
+ -----------
5
+
6
+ - Enable development-mode code reloading. **With Rails 5.0+, you don't need
7
+ to restart Sidekiq to pick up your Sidekiq::Worker changes anymore!** [#2457]
8
+ - **Remove Sinatra dependency**. Sidekiq's Web UI now uses Rack directly.
9
+ Thank you to Sidekiq's newest committer, **badosu**, for writing the code
10
+ and doing a lot of testing to ensure compatibility with many different
11
+ 3rd party plugins. If your Web UI works with 4.1.4 but fails with
12
+ 4.2.0, please open an issue. [#3075]
13
+ - Allow tuning of concurrency with the `RAILS_MAX_THREADS` env var. [#2985]
14
+ This is the same var used by Puma so you can tune all of your systems
15
+ the same way:
16
+ ```sh
17
+ web: RAILS_MAX_THREADS=5 bundle exec puma ...
18
+ worker: RAILS_MAX_THREADS=10 bundle exec sidekiq ...
19
+ ```
20
+ Using `-c` or `config/sidekiq.yml` overrides this setting. I recommend
21
+ adjusting your `config/database.yml` to use it too so connections are
22
+ auto-scaled:
23
+ ```yaml
24
+ pool: <%= ENV['RAILS_MAX_THREADS'] || 5 %>
25
+ ```
26
+
27
+ 4.1.4
28
+ -----------
29
+
30
+ - Unlock Sinatra so a Rails 5.0 compatible version may be used [#3048]
31
+ - Fix race condition on startup with JRuby [#3043]
32
+
33
+
34
+ 4.1.3
35
+ -----------
36
+
37
+ - Please note the Redis 3.3.0 gem has a [memory leak](https://github.com/redis/redis-rb/issues/612),
38
+ Redis 3.2.2 is recommended until that issue is fixed.
39
+ - Sinatra 1.4.x is now a required dependency, avoiding cryptic errors
40
+ and old bugs due to people not upgrading Sinatra for years. [#3042]
41
+ - Fixed race condition in heartbeat which could rarely lead to lingering
42
+ processes on the Busy tab. [#2982]
43
+ ```ruby
44
+ # To clean up lingering processes, modify this as necessary to connect to your Redis.
45
+ # After 60 seconds, lingering processes should disappear from the Busy page.
46
+
47
+ require 'redis'
48
+ r = Redis.new(url: "redis://localhost:6379/0")
49
+ # uncomment if you need a namespace
50
+ #require 'redis-namespace'
51
+ #r = Redis::Namespace.new("foo", r)
52
+ r.smembers("processes").each do |pro|
53
+ r.expire(pro, 60)
54
+ r.expire("#{pro}:workers", 60)
55
+ end
56
+ ```
57
+
58
+
59
+ 4.1.2
60
+ -----------
61
+
62
+ - Fix Redis data leak with worker data when a busy Sidekiq process
63
+ crashes. You can find and expire leaked data in Redis with this
64
+ script:
65
+ ```bash
66
+ $ redis-cli keys "*:workers" | while read LINE ; do TTL=`redis-cli expire "$LINE" 60`; echo "$LINE"; done;
67
+ ```
68
+ Please note that `keys` can be dangerous to run on a large, busy Redis. Caveat runner.
69
+ - Freeze all string literals with Ruby 2.3. [#2741]
70
+ - Client middleware can now stop bulk job push. [#2887]
71
+
3
72
  4.1.1
4
73
  -----------
5
74
 
data/Ent-Changes.md CHANGED
@@ -3,6 +3,46 @@ Sidekiq Enterprise Changelog
3
3
 
4
4
  Please see [http://sidekiq.org/](http://sidekiq.org/) for more details and how to buy.
5
5
 
6
+ 1.3.2
7
+ -------------
8
+
9
+ - Upgrade encryption to use OpenSSL's more secure GCM mode. [#3060]
10
+
11
+ 1.3.1
12
+ -------------
13
+
14
+ - Fix multi-process memory monitoring on CentOS 6.x [#3063]
15
+ - Polish the new encryption feature a bit.
16
+
17
+ 1.3.0
18
+ -------------
19
+
20
+ - **BETA** [New encryption feature](https://github.com/mperham/sidekiq/wiki/Ent-Encryption)
21
+ which automatically encrypts the last argument of a Worker, aka the secret bag.
22
+
23
+ 1.2.4
24
+ -------------
25
+
26
+ - Fix issue causing some minutely jobs to execute every other minute.
27
+ - Log a warning if slow periodic processing causes us to miss a clock tick.
28
+
29
+ 1.2.3
30
+ -------------
31
+
32
+ - Periodic jobs could stop executing until process restart if Redis goes down [#3047]
33
+
34
+ 1.2.2
35
+ -------------
36
+
37
+ - Add API to check if a unique lock is present. See [#2932] for details.
38
+ - Tune concurrent limiters to minimize thread thrashing under heavy contention. [#2944]
39
+ - Add option for tuning which Bundler groups get preloaded with `sidekiqswarm` [#3025]
40
+ ```
41
+ SIDEKIQ_PRELOAD=default,production bin/sidekiqswarm ...
42
+ # Use an empty value for maximum application compatibility
43
+ SIDEKIQ_PRELOAD= bin/sidekiqswarm ...
44
+ ```
45
+
6
46
  1.2.1
7
47
  -------------
8
48
 
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem 'rails', '~> 4.2'
4
+ gem 'rails', '5.0.0'
5
+ gem "hiredis"
5
6
  gem 'simplecov'
6
7
  gem 'minitest'
7
8
  gem 'minitest-utils'
@@ -22,7 +23,7 @@ platforms :mri do
22
23
  gem 'ruby-prof'
23
24
  end
24
25
 
25
- platforms :jruby do
26
- gem 'jruby-openssl'
27
- gem 'activerecord-jdbcsqlite3-adapter'
28
- end
26
+ #platforms :jruby do
27
+ #gem 'jruby-openssl'
28
+ #gem 'activerecord-jdbcsqlite3-adapter'
29
+ #end
data/Pro-3.0-Upgrade.md CHANGED
@@ -17,17 +17,15 @@ Sidekiq Pro 3.0 is designed to work with Sidekiq 4.0.
17
17
  * Reliable fetch has been re-implemented due to the fetch changes in
18
18
  Sidekiq 4.0.
19
19
 
20
- * Support for platforms without persistent hostnames. Since reliable fetch
21
- normally requires a persistent hostname, you may disable hostname usage on
22
- platforms like Heroku and Docker:
20
+ * Support for platforms without persistent hostnames. Since the reliable\_fetch
21
+ algorithm requires a persistent hostname, an alternative reliability
22
+ algorithm is now available for platforms like Heroku and Docker:
23
23
  ```ruby
24
24
  Sidekiq.configure_server do |config|
25
- config.options[:ephemeral_hostname] = true
26
- config.reliable_fetch!
25
+ config.timed_fetch!
27
26
  end
28
27
  ```
29
- This option is enabled automatically if Heroku's DYNO environment variable is present.
30
- Without a persistent hostname, each Sidekiq process **must** have its own unique index.
28
+ The wiki contains [much more detail about each reliability option](https://github.com/mperham/sidekiq/wiki/Pro-Reliability-Server).
31
29
 
32
30
  * The old 'sidekiq/notifications' features have been removed.
33
31
 
data/Pro-Changes.md CHANGED
@@ -3,6 +3,72 @@ Sidekiq Pro Changelog
3
3
 
4
4
  Please see [http://sidekiq.org/](http://sidekiq.org/) for more details and how to buy.
5
5
 
6
+ 3.3.3
7
+ ---------
8
+
9
+ - Update Web UI extension to work with Sidekiq 4.2.0's new Web UI. [#3075]
10
+
11
+ 3.3.2
12
+ ---------
13
+
14
+ - Minimize batch memory usage after success [#3083]
15
+ - Extract batch's 24 hr linger expiry to a LINGER constant so it can be tuned. [#3011]
16
+
17
+ 3.3.1
18
+ ---------
19
+
20
+ - If environment is unset, treat it as development so reliable\_fetch works as before 3.2.2.
21
+
22
+ 3.3.0
23
+ ---------
24
+
25
+ - Don't delete batches immediately upon success but set a 24 hr expiry, this allows
26
+ Sidekiq::Batch::Status#poll to work, even after batch success. [#3011]
27
+ - New `Sidekiq::PendingSet#destroy(jid)` API to remove poison pill jobs [#3015]
28
+
29
+ 3.2.2
30
+ ---------
31
+
32
+ - A default value for -i is only set in development now, staging or
33
+ other environments must set an index if you wish to use reliable\_fetch. [#2971]
34
+ - Fix nil dereference when checking for jobs over timeout in timed\_fetch
35
+
36
+
37
+ 3.2.1
38
+ ---------
39
+
40
+ - timed\_fetch now works with namespaces. [ryansch]
41
+
42
+
43
+ 3.2.0
44
+ ---------
45
+
46
+ - Fixed detection of missing batches, `NoSuchBatch` should be raised
47
+ properly now if `Sidekiq::Batch.new(bid)` is called on a batch no
48
+ longer in Redis.
49
+ - Remove support for Pro 1.x format batches. This version will no
50
+ longer seamlessly process batches created with Sidekiq Pro 1.x.
51
+ As always, upgrade one major version at a time to ensure a smooth
52
+ transition.
53
+ - Fix edge case where a parent batch could expire before a child batch
54
+ was finished processing, leading to missing batches [#2889]
55
+
56
+ 2.1.5
57
+ ---------
58
+
59
+ - Fix edge case where a parent batch could expire before a child batch
60
+ was finished processing, leading to missing batches [#2889]
61
+
62
+ 3.1.0
63
+ ---------
64
+
65
+ - New container-friendly fetch algorithm: `timed_fetch`. See the
66
+ [wiki documentation](https://github.com/mperham/sidekiq/wiki/Pro-Reliability-Server)
67
+ for trade offs between the two reliability options. You should
68
+ use this if you are on Heroku, Docker, Amazon ECS or EBS or
69
+ another container-based system.
70
+
71
+
6
72
  3.0.6
7
73
  ---------
8
74
 
data/README.md CHANGED
@@ -18,7 +18,8 @@ message format as Resque so it can integrate into an existing Resque processing
18
18
  You can have Sidekiq and Resque run side-by-side at the same time and
19
19
  use the Resque client to enqueue jobs in Redis to be processed by Sidekiq.
20
20
 
21
- Sidekiq is fast.
21
+ Performance
22
+ ---------------
22
23
 
23
24
  Version | Latency | Garbage created for 10,000 jobs | Time to process 100,000 jobs | Throughput
24
25
  -----------------|------|---------|---------|------------------------
data/bin/sidekiqload CHANGED
@@ -26,8 +26,8 @@ Toxiproxy.populate([{
26
26
 
27
27
 
28
28
  Sidekiq.configure_server do |config|
29
- config.redis = { db: 13, port: 6380 }
30
- #config.redis = { db: 13 }
29
+ #config.options[:concurrency] = 1
30
+ config.redis = { driver: :hiredis, db: 13, port: 6380 }
31
31
  config.options[:queues] << 'default'
32
32
  config.logger.level = Logger::ERROR
33
33
  config.average_scheduled_poll_interval = 2
data/lib/sidekiq.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: utf-8
2
3
  require 'sidekiq/version'
3
4
  fail "Sidekiq #{Sidekiq::VERSION} does not support Ruby versions below 2.0.0." if RUBY_PLATFORM != 'java' && RUBY_VERSION < '2.0.0'
@@ -27,9 +28,11 @@ module Sidekiq
27
28
  startup: [],
28
29
  quiet: [],
29
30
  shutdown: [],
31
+ heartbeat: [],
30
32
  },
31
33
  dead_max_jobs: 10_000,
32
- dead_timeout_in_seconds: 180 * 24 * 60 * 60 # 6 months
34
+ dead_timeout_in_seconds: 180 * 24 * 60 * 60, # 6 months
35
+ reloader: proc { |&block| block.call },
33
36
  }
34
37
 
35
38
  DEFAULT_WORKER_OPTIONS = {
@@ -168,6 +171,7 @@ module Sidekiq
168
171
  def self.default_retries_exhausted=(prok)
169
172
  @default_retries_exhausted = prok
170
173
  end
174
+ @default_retries_exhausted = ->(job, ex) { }
171
175
  def self.default_retries_exhausted
172
176
  @default_retries_exhausted
173
177
  end
data/lib/sidekiq/api.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: utf-8
2
3
  require 'sidekiq'
3
4
 
@@ -195,7 +196,7 @@ module Sidekiq
195
196
  # Return all known queues within Redis.
196
197
  #
197
198
  def self.all
198
- Sidekiq.redis {|c| c.smembers('queues'.freeze) }.sort.map {|q| Sidekiq::Queue.new(q) }
199
+ Sidekiq.redis { |c| c.smembers('queues'.freeze) }.sort.map { |q| Sidekiq::Queue.new(q) }
199
200
  end
200
201
 
201
202
  attr_reader :name
@@ -277,6 +278,7 @@ module Sidekiq
277
278
  #
278
279
  class Job
279
280
  attr_reader :item
281
+ attr_reader :value
280
282
 
281
283
  def initialize(item, queue_name=nil)
282
284
  @value = item
data/lib/sidekiq/cli.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: utf-8
2
3
  $stdout.sync = true
3
4
 
@@ -70,6 +71,9 @@ module Sidekiq
70
71
  ver = Sidekiq.redis_info['redis_version']
71
72
  raise "You are using Redis v#{ver}, Sidekiq requires Redis v2.8.0 or greater" if ver < '2.8'
72
73
 
74
+ # Touch middleware so it isn't lazy loaded by multiple threads, #3043
75
+ Sidekiq.server_middleware
76
+
73
77
  # Before this point, the process is initializing with just the main thread.
74
78
  # Starting here the process will now have multiple threads running.
75
79
  fire_event(:startup)
@@ -204,6 +208,8 @@ module Sidekiq
204
208
  opts = parse_config(cfile).merge(opts) if cfile
205
209
 
206
210
  opts[:strict] = true if opts[:strict].nil?
211
+ opts[:concurrency] = Integer(ENV["RAILS_MAX_THREADS"]) if !opts[:concurrency] && ENV["RAILS_MAX_THREADS"]
212
+ opts[:identity] = identity
207
213
 
208
214
  options.merge!(opts)
209
215
  end
@@ -223,7 +229,7 @@ module Sidekiq
223
229
  require 'sidekiq/rails'
224
230
  require File.expand_path("#{options[:require]}/config/environment.rb")
225
231
  ::Rails.application.eager_load!
226
- else
232
+ elsif ::Rails::VERSION::MAJOR == 4
227
233
  # Painful contortions, see 1791 for discussion
228
234
  require File.expand_path("#{options[:require]}/config/application.rb")
229
235
  ::Rails::Application.initializer "sidekiq.eager_load" do
@@ -231,10 +237,17 @@ module Sidekiq
231
237
  end
232
238
  require 'sidekiq/rails'
233
239
  require File.expand_path("#{options[:require]}/config/environment.rb")
240
+ else
241
+ require 'sidekiq/rails'
242
+ require File.expand_path("#{options[:require]}/config/environment.rb")
243
+ Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new
234
244
  end
235
245
  options[:tag] ||= default_tag
236
246
  else
237
- require options[:require]
247
+ not_required_message = "#{options[:require]} was not required, you should use an explicit path: " +
248
+ "./#{options[:require]} or /path/to/#{options[:require]}"
249
+
250
+ require(options[:require]) || raise(ArgumentError, not_required_message)
238
251
  end
239
252
  end
240
253
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'securerandom'
2
3
  require 'sidekiq/middleware/chain'
3
4
 
@@ -82,10 +83,15 @@ module Sidekiq
82
83
  # Returns an array of the of pushed jobs' jids. The number of jobs pushed can be less
83
84
  # than the number given if the middleware stopped processing for one or more jobs.
84
85
  def push_bulk(items)
86
+ arg = items['args'].first
87
+ return [] unless arg # no jobs to push
88
+ raise ArgumentError, "Bulk arguments must be an Array of Arrays: [[1], [2]]" if !arg.is_a?(Array)
89
+
85
90
  normed = normalize_item(items)
86
91
  payloads = items['args'].map do |args|
87
- raise ArgumentError, "Bulk arguments must be an Array of Arrays: [[1], [2]]" if !args.is_a?(Array)
88
- process_single(items['class'], normed.merge('args' => args, 'jid' => SecureRandom.hex(12), 'enqueued_at' => Time.now.to_f))
92
+ copy = normed.merge('args' => args, 'jid' => SecureRandom.hex(12), 'enqueued_at' => Time.now.to_f)
93
+ result = process_single(items['class'], copy)
94
+ result ? result : nil
89
95
  end.compact
90
96
 
91
97
  raw_push(payloads) if !payloads.empty?
@@ -106,7 +112,8 @@ module Sidekiq
106
112
  # you cannot scale any other way (e.g. splitting your app into smaller apps).
107
113
  def self.via(pool)
108
114
  raise ArgumentError, "No pool given" if pool.nil?
109
- raise RuntimeError, "Sidekiq::Client.via is not re-entrant" if x = Thread.current[:sidekiq_via_pool] && x != pool
115
+ current_sidekiq_pool = Thread.current[:sidekiq_via_pool]
116
+ raise RuntimeError, "Sidekiq::Client.via is not re-entrant" if current_sidekiq_pool && current_sidekiq_pool != pool
110
117
  Thread.current[:sidekiq_via_pool] = pool
111
118
  yield
112
119
  ensure
@@ -205,6 +212,7 @@ module Sidekiq
205
212
  raise(ArgumentError, "Job must be a Hash with 'class' and 'args' keys: { 'class' => SomeWorker, 'args' => ['bob', 1, :foo => 'bar'] }") unless item.is_a?(Hash) && item.has_key?('class'.freeze) && item.has_key?('args'.freeze)
206
213
  raise(ArgumentError, "Job args must be an Array") unless item['args'].is_a?(Array)
207
214
  raise(ArgumentError, "Job class must be either a Class or String representation of the class name") unless item['class'.freeze].is_a?(Class) || item['class'.freeze].is_a?(String)
215
+ #raise(ArgumentError, "Arguments must be native JSON types, see https://github.com/mperham/sidekiq/wiki/Best-Practices") unless JSON.load(JSON.dump(item['args'])) == item['args']
208
216
 
209
217
  normalized_hash(item['class'.freeze])
210
218
  .each{ |key, value| item[key] = value if item[key].nil? }