sidekiq 4.2.4 → 5.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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +8 -1
  3. data/.gitignore +1 -0
  4. data/.travis.yml +5 -3
  5. data/5.0-Upgrade.md +56 -0
  6. data/COMM-LICENSE +1 -1
  7. data/Changes.md +151 -0
  8. data/Ent-Changes.md +77 -2
  9. data/Gemfile +10 -25
  10. data/LICENSE +1 -1
  11. data/Pro-4.0-Upgrade.md +35 -0
  12. data/Pro-Changes.md +156 -2
  13. data/README.md +9 -6
  14. data/Rakefile +1 -2
  15. data/bin/sidekiqctl +1 -1
  16. data/bin/sidekiqload +15 -33
  17. data/lib/generators/sidekiq/templates/worker_spec.rb.erb +1 -1
  18. data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
  19. data/lib/sidekiq/api.rb +157 -67
  20. data/lib/sidekiq/cli.rb +71 -26
  21. data/lib/sidekiq/client.rb +25 -18
  22. data/lib/sidekiq/core_ext.rb +1 -106
  23. data/lib/sidekiq/delay.rb +42 -0
  24. data/lib/sidekiq/exception_handler.rb +2 -4
  25. data/lib/sidekiq/extensions/generic_proxy.rb +7 -1
  26. data/lib/sidekiq/fetch.rb +1 -1
  27. data/lib/sidekiq/job_logger.rb +25 -0
  28. data/lib/sidekiq/job_retry.rb +241 -0
  29. data/lib/sidekiq/launcher.rb +45 -37
  30. data/lib/sidekiq/logging.rb +18 -2
  31. data/lib/sidekiq/manager.rb +3 -4
  32. data/lib/sidekiq/middleware/server/active_record.rb +10 -0
  33. data/lib/sidekiq/processor.rb +91 -34
  34. data/lib/sidekiq/rails.rb +15 -51
  35. data/lib/sidekiq/redis_connection.rb +31 -5
  36. data/lib/sidekiq/scheduled.rb +35 -8
  37. data/lib/sidekiq/testing.rb +24 -7
  38. data/lib/sidekiq/util.rb +6 -2
  39. data/lib/sidekiq/version.rb +1 -1
  40. data/lib/sidekiq/web/action.rb +2 -6
  41. data/lib/sidekiq/web/application.rb +28 -21
  42. data/lib/sidekiq/web/helpers.rb +67 -23
  43. data/lib/sidekiq/web/router.rb +14 -10
  44. data/lib/sidekiq/web.rb +4 -4
  45. data/lib/sidekiq/worker.rb +97 -14
  46. data/lib/sidekiq.rb +23 -24
  47. data/sidekiq.gemspec +7 -10
  48. data/web/assets/javascripts/application.js +0 -0
  49. data/web/assets/javascripts/dashboard.js +18 -13
  50. data/web/assets/stylesheets/application-rtl.css +246 -0
  51. data/web/assets/stylesheets/application.css +336 -4
  52. data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
  53. data/web/assets/stylesheets/bootstrap.css +2 -2
  54. data/web/locales/ar.yml +80 -0
  55. data/web/locales/en.yml +1 -0
  56. data/web/locales/es.yml +4 -3
  57. data/web/locales/fa.yml +80 -0
  58. data/web/locales/he.yml +79 -0
  59. data/web/locales/ja.yml +5 -3
  60. data/web/locales/ur.yml +80 -0
  61. data/web/views/_footer.erb +5 -2
  62. data/web/views/_job_info.erb +1 -1
  63. data/web/views/_nav.erb +1 -1
  64. data/web/views/_paging.erb +1 -1
  65. data/web/views/busy.erb +9 -5
  66. data/web/views/dashboard.erb +3 -3
  67. data/web/views/layout.erb +11 -2
  68. data/web/views/morgue.erb +14 -10
  69. data/web/views/queue.erb +10 -10
  70. data/web/views/queues.erb +4 -2
  71. data/web/views/retries.erb +13 -11
  72. data/web/views/retry.erb +1 -1
  73. data/web/views/scheduled.erb +2 -2
  74. metadata +26 -160
  75. data/lib/sidekiq/middleware/server/logging.rb +0 -40
  76. data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -205
  77. data/test/config.yml +0 -9
  78. data/test/env_based_config.yml +0 -11
  79. data/test/fake_env.rb +0 -1
  80. data/test/fixtures/en.yml +0 -2
  81. data/test/helper.rb +0 -75
  82. data/test/test_actors.rb +0 -138
  83. data/test/test_api.rb +0 -528
  84. data/test/test_cli.rb +0 -418
  85. data/test/test_client.rb +0 -266
  86. data/test/test_exception_handler.rb +0 -56
  87. data/test/test_extensions.rb +0 -127
  88. data/test/test_fetch.rb +0 -50
  89. data/test/test_launcher.rb +0 -95
  90. data/test/test_logging.rb +0 -35
  91. data/test/test_manager.rb +0 -50
  92. data/test/test_middleware.rb +0 -158
  93. data/test/test_processor.rb +0 -235
  94. data/test/test_rails.rb +0 -22
  95. data/test/test_redis_connection.rb +0 -132
  96. data/test/test_retry.rb +0 -326
  97. data/test/test_retry_exhausted.rb +0 -149
  98. data/test/test_scheduled.rb +0 -115
  99. data/test/test_scheduling.rb +0 -58
  100. data/test/test_sidekiq.rb +0 -107
  101. data/test/test_testing.rb +0 -143
  102. data/test/test_testing_fake.rb +0 -357
  103. data/test/test_testing_inline.rb +0 -94
  104. data/test/test_util.rb +0 -13
  105. data/test/test_web.rb +0 -726
  106. data/test/test_web_helpers.rb +0 -54
data/lib/sidekiq/web.rb CHANGED
@@ -19,10 +19,10 @@ require 'rack/session/cookie'
19
19
  module Sidekiq
20
20
  class Web
21
21
  ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../web")
22
- VIEWS = "#{ROOT}/views".freeze
23
- LOCALES = ["#{ROOT}/locales".freeze]
24
- LAYOUT = "#{VIEWS}/layout.erb".freeze
25
- ASSETS = "#{ROOT}/assets".freeze
22
+ VIEWS = "#{ROOT}/views"
23
+ LOCALES = ["#{ROOT}/locales"]
24
+ LAYOUT = "#{VIEWS}/layout.erb"
25
+ ASSETS = "#{ROOT}/assets"
26
26
 
27
27
  DEFAULT_TABS = {
28
28
  "Dashboard" => '',
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  require 'sidekiq/client'
3
- require 'sidekiq/core_ext'
4
3
 
5
4
  module Sidekiq
6
5
 
@@ -28,15 +27,44 @@ module Sidekiq
28
27
  raise ArgumentError, "You cannot include Sidekiq::Worker in an ActiveJob: #{base.name}" if base.ancestors.any? {|c| c.name == 'ActiveJob::Base' }
29
28
 
30
29
  base.extend(ClassMethods)
31
- base.class_attribute :sidekiq_options_hash
32
- base.class_attribute :sidekiq_retry_in_block
33
- base.class_attribute :sidekiq_retries_exhausted_block
30
+ base.sidekiq_class_attribute :sidekiq_options_hash
31
+ base.sidekiq_class_attribute :sidekiq_retry_in_block
32
+ base.sidekiq_class_attribute :sidekiq_retries_exhausted_block
34
33
  end
35
34
 
36
35
  def logger
37
36
  Sidekiq.logger
38
37
  end
39
38
 
39
+ # This helper class encapsulates the set options for `set`, e.g.
40
+ #
41
+ # SomeWorker.set(queue: 'foo').perform_async(....)
42
+ #
43
+ class Setter
44
+ def initialize(klass, opts)
45
+ @klass = klass
46
+ @opts = opts
47
+ end
48
+
49
+ def perform_async(*args)
50
+ @klass.client_push(@opts.merge('args' => args, 'class' => @klass))
51
+ end
52
+
53
+ # +interval+ must be a timestamp, numeric or something that acts
54
+ # numeric (like an activesupport time interval).
55
+ def perform_in(interval, *args)
56
+ int = interval.to_f
57
+ now = Time.now.to_f
58
+ ts = (int < 1_000_000_000 ? now + int : int)
59
+
60
+ payload = @opts.merge('class' => @klass, 'args' => args, 'at' => ts)
61
+ # Optimization to enqueue something now that is scheduled to go out now or in the past
62
+ payload.delete('at') if ts <= now
63
+ @klass.client_push(payload)
64
+ end
65
+ alias_method :perform_at, :perform_in
66
+ end
67
+
40
68
  module ClassMethods
41
69
 
42
70
  def delay(*args)
@@ -52,8 +80,7 @@ module Sidekiq
52
80
  end
53
81
 
54
82
  def set(options)
55
- Thread.current[:sidekiq_worker_set] = options
56
- self
83
+ Setter.new(self, options)
57
84
  end
58
85
 
59
86
  def perform_async(*args)
@@ -70,7 +97,7 @@ module Sidekiq
70
97
  item = { 'class' => self, 'args' => args, 'at' => ts }
71
98
 
72
99
  # Optimization to enqueue something now that is scheduled to go out now or in the past
73
- item.delete('at'.freeze) if ts <= now
100
+ item.delete('at') if ts <= now
74
101
 
75
102
  client_push(item)
76
103
  end
@@ -90,7 +117,8 @@ module Sidekiq
90
117
  # In practice, any option is allowed. This is the main mechanism to configure the
91
118
  # options for a specific job.
92
119
  def sidekiq_options(opts={})
93
- self.sidekiq_options_hash = get_sidekiq_options.merge(opts.stringify_keys)
120
+ # stringify
121
+ self.sidekiq_options_hash = get_sidekiq_options.merge(Hash[opts.map{|k, v| [k.to_s, v]}])
94
122
  end
95
123
 
96
124
  def sidekiq_retry_in(&block)
@@ -107,13 +135,68 @@ module Sidekiq
107
135
 
108
136
  def client_push(item) # :nodoc:
109
137
  pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options['pool'] || Sidekiq.redis_pool
110
- hash = if Thread.current[:sidekiq_worker_set]
111
- x, Thread.current[:sidekiq_worker_set] = Thread.current[:sidekiq_worker_set], nil
112
- x.stringify_keys.merge(item.stringify_keys)
113
- else
114
- item.stringify_keys
138
+ # stringify
139
+ item.keys.each do |key|
140
+ item[key.to_s] = item.delete(key)
141
+ end
142
+
143
+ Sidekiq::Client.new(pool).push(item)
144
+ end
145
+
146
+ def sidekiq_class_attribute(*attrs)
147
+ instance_reader = true
148
+ instance_writer = true
149
+
150
+ attrs.each do |name|
151
+ singleton_class.instance_eval do
152
+ undef_method(name) if method_defined?(name) || private_method_defined?(name)
153
+ end
154
+ define_singleton_method(name) { nil }
155
+
156
+ ivar = "@#{name}"
157
+
158
+ singleton_class.instance_eval do
159
+ m = "#{name}="
160
+ undef_method(m) if method_defined?(m) || private_method_defined?(m)
161
+ end
162
+ define_singleton_method("#{name}=") do |val|
163
+ singleton_class.class_eval do
164
+ undef_method(name) if method_defined?(name) || private_method_defined?(name)
165
+ define_method(name) { val }
166
+ end
167
+
168
+ if singleton_class?
169
+ class_eval do
170
+ undef_method(name) if method_defined?(name) || private_method_defined?(name)
171
+ define_method(name) do
172
+ if instance_variable_defined? ivar
173
+ instance_variable_get ivar
174
+ else
175
+ singleton_class.send name
176
+ end
177
+ end
178
+ end
179
+ end
180
+ val
181
+ end
182
+
183
+ if instance_reader
184
+ undef_method(name) if method_defined?(name) || private_method_defined?(name)
185
+ define_method(name) do
186
+ if instance_variable_defined?(ivar)
187
+ instance_variable_get ivar
188
+ else
189
+ self.class.public_send name
190
+ end
191
+ end
192
+ end
193
+
194
+ if instance_writer
195
+ m = "#{name}="
196
+ undef_method(m) if method_defined?(m) || private_method_defined?(m)
197
+ attr_writer name
198
+ end
115
199
  end
116
- Sidekiq::Client.new(pool).push(hash)
117
200
  end
118
201
 
119
202
  end
data/lib/sidekiq.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
- # encoding: utf-8
3
2
  require 'sidekiq/version'
4
- fail "Sidekiq #{Sidekiq::VERSION} does not support Ruby versions below 2.0.0." if RUBY_PLATFORM != 'java' && RUBY_VERSION < '2.0.0'
3
+ fail "Sidekiq #{Sidekiq::VERSION} does not support Ruby versions below 2.2.2." if RUBY_PLATFORM != 'java' && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
5
4
 
6
5
  require 'sidekiq/logging'
7
6
  require 'sidekiq/client'
8
7
  require 'sidekiq/worker'
9
8
  require 'sidekiq/redis_connection'
9
+ require 'sidekiq/delay'
10
10
 
11
11
  require 'json'
12
12
 
@@ -17,13 +17,14 @@ module Sidekiq
17
17
  DEFAULTS = {
18
18
  queues: [],
19
19
  labels: [],
20
- concurrency: 25,
20
+ concurrency: 10,
21
21
  require: '.',
22
22
  environment: nil,
23
23
  timeout: 8,
24
24
  poll_interval_average: nil,
25
- average_scheduled_poll_interval: 15,
25
+ average_scheduled_poll_interval: 5,
26
26
  error_handlers: [],
27
+ death_handlers: [],
27
28
  lifecycle_events: {
28
29
  startup: [],
29
30
  quiet: [],
@@ -46,7 +47,7 @@ module Sidekiq
46
47
  "connected_clients" => "9999",
47
48
  "used_memory_human" => "9P",
48
49
  "used_memory_peak_human" => "9P"
49
- }.freeze
50
+ }
50
51
 
51
52
  def self.❨╯°□°❩╯︵┻━┻
52
53
  puts "Calm down, yo."
@@ -144,32 +145,34 @@ module Sidekiq
144
145
  end
145
146
 
146
147
  def self.default_server_middleware
147
- require 'sidekiq/middleware/server/retry_jobs'
148
- require 'sidekiq/middleware/server/logging'
149
-
150
- Middleware::Chain.new do |m|
151
- m.add Middleware::Server::Logging
152
- m.add Middleware::Server::RetryJobs
153
- end
148
+ Middleware::Chain.new
154
149
  end
155
150
 
156
151
  def self.default_worker_options=(hash)
157
- @default_worker_options = default_worker_options.merge(hash.stringify_keys)
152
+ # stringify
153
+ @default_worker_options = default_worker_options.merge(Hash[hash.map{|k, v| [k.to_s, v]}])
158
154
  end
159
155
  def self.default_worker_options
160
156
  defined?(@default_worker_options) ? @default_worker_options : DEFAULT_WORKER_OPTIONS
161
157
  end
162
158
 
159
+ def self.default_retries_exhausted=(prok)
160
+ logger.info { "default_retries_exhausted is deprecated, please use `config.death_handlers << -> {|job, ex| }`" }
161
+ return nil unless prok
162
+ death_handlers << prok
163
+ end
164
+
165
+ ##
166
+ # Death handlers are called when all retries for a job have been exhausted and
167
+ # the job dies. It's the notification to your application
168
+ # that this job will not succeed without manual intervention.
169
+ #
163
170
  # Sidekiq.configure_server do |config|
164
- # config.default_retries_exhausted = -> (job, ex) do
171
+ # config.death_handlers << ->(job, ex) do
165
172
  # end
166
173
  # end
167
- def self.default_retries_exhausted=(prok)
168
- @default_retries_exhausted = prok
169
- end
170
- @default_retries_exhausted = ->(job, ex) { }
171
- def self.default_retries_exhausted
172
- @default_retries_exhausted
174
+ def self.death_handlers
175
+ options[:death_handlers]
173
176
  end
174
177
 
175
178
  def self.load_json(string)
@@ -227,10 +230,6 @@ module Sidekiq
227
230
  # otherwise Ruby's Thread#kill will commit. See #377.
228
231
  # DO NOT RESCUE THIS ERROR IN YOUR WORKERS
229
232
  class Shutdown < Interrupt; end
230
-
231
233
  end
232
234
 
233
- require 'sidekiq/extensions/class_methods'
234
- require 'sidekiq/extensions/action_mailer'
235
- require 'sidekiq/extensions/active_record'
236
235
  require 'sidekiq/rails' if defined?(::Rails::Engine)
data/sidekiq.gemspec CHANGED
@@ -10,17 +10,14 @@ Gem::Specification.new do |gem|
10
10
  gem.license = "LGPL-3.0"
11
11
 
12
12
  gem.executables = ['sidekiq', 'sidekiqctl']
13
- gem.files = `git ls-files | grep -Ev '^(myapp|examples)'`.split("\n")
14
- gem.test_files = `git ls-files -- test/*`.split("\n")
13
+ gem.files = `git ls-files | grep -Ev '^(test|myapp|examples)'`.split("\n")
14
+ gem.test_files = []
15
15
  gem.name = "sidekiq"
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = Sidekiq::VERSION
18
- gem.add_dependency 'redis', '~> 3.2', '>= 3.2.1'
19
- gem.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.0'
20
- gem.add_dependency 'concurrent-ruby', '~> 1.0'
21
- gem.add_dependency 'rack-protection', '>= 1.5.0'
22
- gem.add_development_dependency 'redis-namespace', '~> 1.5', '>= 1.5.2'
23
- gem.add_development_dependency 'minitest', '~> 5.7', '>= 5.7.0'
24
- gem.add_development_dependency 'rake', '~> 10.0'
25
- gem.add_development_dependency 'rails', '>= 3.2.0'
18
+ gem.required_ruby_version = ">= 2.2.2"
19
+
20
+ gem.add_dependency 'redis', '>= 3.3.5', '< 5'
21
+ gem.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.2'
22
+ gem.add_dependency 'rack-protection', '>= 1.5.0'
26
23
  end
File without changes