sidekiq 4.2.5 → 4.2.6

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a2578c1e0ac05d0f59c8ec89ac300e8c8dab429
4
- data.tar.gz: 180b80981a6d6043b6aec7222f16d9ab2d5f93a8
3
+ metadata.gz: 2dca1b4492db20ca793becbe891322c358858157
4
+ data.tar.gz: 89782986b48def18330d996488e4b823946d5963
5
5
  SHA512:
6
- metadata.gz: 60a192e270a1d867cb8c3787aebd46f6ffcb6bd5a6f63fd61519d83ef93ab46b44658d32d671139fb7a33a55dc5641b4e9793ebda1a82f69fa5105d19ac8ce3b
7
- data.tar.gz: df14db1cc745182b29b7d8924a51759ff1fe01a1331959af53fde65eeab456dde03f52e85ddacc39a92ce6b27eead378a3ea30c3d5da5e8ea77b13007218f21f
6
+ metadata.gz: f4ff8bfb9436c9508bfbf4d72d66156f940fa4372ae5237124442fc80ef21dd51237b44c3fc8aafab6f798f2b1576f09522ce60ade66748566df5c7c392fc7eb
7
+ data.tar.gz: 0e21ba4873492e74370b62b4cec47a38383115cc85f9a25b4b695ec54e392fea6f771580e315c8037eb78a0d1309651a08849aea4ea5ec378811650a55237377
data/Changes.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Sidekiq Changes
2
2
 
3
+ 4.2.6
4
+ -----------
5
+
6
+ - Run Rails Executor when in production [#3221, eugeneius]
7
+
3
8
  4.2.5
4
9
  -----------
5
10
 
data/README.md CHANGED
@@ -50,7 +50,8 @@ Getting Started
50
50
  -----------------
51
51
 
52
52
  See the [Getting Started wiki page](https://github.com/mperham/sidekiq/wiki/Getting-Started) and follow the simple setup process.
53
- You can watch [Railscast #366](http://railscasts.com/episodes/366-sidekiq) to see Sidekiq in action. If you do everything right, you should see this:
53
+ You can watch [this Youtube playlist](https://www.youtube.com/playlist?list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1) to learn all about
54
+ Sidekiq and see its features in action. Here's the Web UI:
54
55
 
55
56
  ![Web UI](https://github.com/mperham/sidekiq/raw/master/examples/web-ui.png)
56
57
 
@@ -12,19 +12,6 @@ require_relative '../lib/sidekiq/launcher'
12
12
 
13
13
  include Sidekiq::Util
14
14
 
15
- # brew tap shopify/shopify
16
- # brew install toxiproxy
17
- # gem install toxiproxy
18
- require 'toxiproxy'
19
- # simulate a non-localhost network for realer-world conditions.
20
- # adding 1ms of network latency has an ENORMOUS impact on benchmarks
21
- Toxiproxy.populate([{
22
- "name": "redis",
23
- "listen": "127.0.0.1:6380",
24
- "upstream": "127.0.0.1:6379"
25
- }])
26
-
27
-
28
15
  Sidekiq.configure_server do |config|
29
16
  #config.options[:concurrency] = 1
30
17
  config.redis = { driver: :hiredis, db: 13, port: 6380 }
@@ -33,6 +33,7 @@ module Sidekiq
33
33
  dead_max_jobs: 10_000,
34
34
  dead_timeout_in_seconds: 180 * 24 * 60 * 60, # 6 months
35
35
  reloader: proc { |&block| block.call },
36
+ executor: proc { |&block| block.call },
36
37
  }
37
38
 
38
39
  DEFAULT_WORKER_OPTIONS = {
@@ -37,6 +37,7 @@ module Sidekiq
37
37
  @thread = nil
38
38
  @strategy = (mgr.options[:fetch] || Sidekiq::BasicFetch).new(mgr.options)
39
39
  @reloader = Sidekiq.options[:reloader]
40
+ @executor = Sidekiq.options[:executor]
40
41
  end
41
42
 
42
43
  def terminate(wait=false)
@@ -121,19 +122,21 @@ module Sidekiq
121
122
 
122
123
  ack = false
123
124
  begin
125
+ job_hash = Sidekiq.load_json(jobstr)
124
126
  @reloader.call do
125
- job = Sidekiq.load_json(jobstr)
126
- klass = job['class'.freeze].constantize
127
+ klass = job_hash['class'.freeze].constantize
127
128
  worker = klass.new
128
- worker.jid = job['jid'.freeze]
129
-
130
- stats(worker, job, queue) do
131
- Sidekiq.server_middleware.invoke(worker, job, queue) do
132
- # Only ack if we either attempted to start this job or
133
- # successfully completed it. This prevents us from
134
- # losing jobs if a middleware raises an exception before yielding
135
- ack = true
136
- execute_job(worker, cloned(job['args'.freeze]))
129
+ worker.jid = job_hash['jid'.freeze]
130
+
131
+ stats(worker, job_hash, queue) do
132
+ Sidekiq.server_middleware.invoke(worker, job_hash, queue) do
133
+ @executor.call do
134
+ # Only ack if we either attempted to start this job or
135
+ # successfully completed it. This prevents us from
136
+ # losing jobs if a middleware raises an exception before yielding
137
+ ack = true
138
+ execute_job(worker, cloned(job_hash['args'.freeze]))
139
+ end
137
140
  end
138
141
  end
139
142
  ack = true
@@ -144,7 +147,7 @@ module Sidekiq
144
147
  # we didn't properly finish it.
145
148
  ack = false
146
149
  rescue Exception => ex
147
- handle_exception(ex, { :context => "Job raised exception", :job => job, :jobstr => jobstr })
150
+ handle_exception(ex, { :context => "Job raised exception", :job => job_hash, :jobstr => jobstr })
148
151
  raise
149
152
  ensure
150
153
  work.acknowledge if ack
@@ -163,9 +166,9 @@ module Sidekiq
163
166
  PROCESSED = Concurrent::AtomicFixnum.new
164
167
  FAILURE = Concurrent::AtomicFixnum.new
165
168
 
166
- def stats(worker, job, queue)
169
+ def stats(worker, job_hash, queue)
167
170
  tid = thread_identity
168
- WORKER_STATE[tid] = {:queue => queue, :payload => cloned(job), :run_at => Time.now.to_i }
171
+ WORKER_STATE[tid] = {:queue => queue, :payload => cloned(job_hash), :run_at => Time.now.to_i }
169
172
 
170
173
  begin
171
174
  yield
@@ -67,15 +67,32 @@ module Sidekiq
67
67
  # The reloader API has proven to be troublesome under load in production.
68
68
  # We won't use it at all when classes are cached, see #3154
69
69
  Sidekiq.logger.debug { "Autoload disabled in #{::Rails.env}, Sidekiq will not reload changed classes" }
70
+ Sidekiq.options[:executor] = Sidekiq::Rails::Executor.new
70
71
  else
72
+ Sidekiq.logger.debug { "Enabling Rails 5+ live code reloading, so hot!" }
71
73
  Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new
72
74
  end
73
75
  end
74
76
  end
75
77
 
78
+ class Executor
79
+ def initialize(app = ::Rails.application)
80
+ @app = app
81
+ end
82
+
83
+ def call
84
+ @app.executor.wrap do
85
+ yield
86
+ end
87
+ end
88
+
89
+ def inspect
90
+ "#<Sidekiq::Rails::Executor @app=#{@app.class.name}>"
91
+ end
92
+ end
93
+
76
94
  class Reloader
77
95
  def initialize(app = ::Rails.application)
78
- Sidekiq.logger.debug "Enabling Rails 5+ live code reloading, so hot!" unless app.config.cache_classes
79
96
  @app = app
80
97
  end
81
98
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Sidekiq
3
- VERSION = "4.2.5"
3
+ VERSION = "4.2.6"
4
4
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'uri'
3
+ require 'set'
3
4
  require 'yaml'
4
5
 
5
6
  module Sidekiq
@@ -67,7 +67,11 @@ class TestProcessor < Sidekiq::Test
67
67
 
68
68
  describe 'exception handling' do
69
69
  let(:errors) { [] }
70
- let(:error_handler) { proc { |ex, _| errors << ex } }
70
+ let(:error_handler) do
71
+ proc do |exception, context|
72
+ errors << { exception: exception, context: context }
73
+ end
74
+ end
71
75
 
72
76
  before do
73
77
  Sidekiq.error_handlers << error_handler
@@ -78,24 +82,34 @@ class TestProcessor < Sidekiq::Test
78
82
  end
79
83
 
80
84
  it 'handles exceptions raised by the job' do
81
- msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['boom'] })
85
+ job_hash = { 'class' => MockWorker.to_s, 'args' => ['boom'] }
86
+ msg = Sidekiq.dump_json(job_hash)
87
+ job = work(msg)
82
88
  begin
83
- @processor.process(work(msg))
89
+ @processor.instance_variable_set(:'@job', job)
90
+ @processor.process(job)
84
91
  rescue TestException
85
92
  end
86
93
  assert_equal 1, errors.count
87
- assert_instance_of TestException, errors.first
94
+ assert_instance_of TestException, errors.first[:exception]
95
+ assert_equal msg, errors.first[:context][:jobstr]
96
+ assert_equal job_hash, errors.first[:context][:job]
88
97
  end
89
98
 
90
99
  it 'handles exceptions raised by the reloader' do
91
- msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
100
+ job_hash = { 'class' => MockWorker.to_s, 'args' => ['boom'] }
101
+ msg = Sidekiq.dump_json(job_hash)
92
102
  @processor.instance_variable_set(:'@reloader', proc { raise TEST_EXCEPTION })
103
+ job = work(msg)
93
104
  begin
94
- @processor.process(work(msg))
105
+ @processor.instance_variable_set(:'@job', job)
106
+ @processor.process(job)
95
107
  rescue TestException
96
108
  end
97
109
  assert_equal 1, errors.count
98
- assert_instance_of TestException, errors.first
110
+ assert_instance_of TestException, errors.first[:exception]
111
+ assert_equal msg, errors.first[:context][:jobstr]
112
+ assert_equal job_hash, errors.first[:context][:job]
99
113
  end
100
114
  end
101
115
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.5
4
+ version: 4.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-04 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis