sidekiq 5.1.1 → 5.2.2
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 +4 -4
- data/.travis.yml +5 -5
- data/Changes.md +39 -0
- data/Ent-Changes.md +11 -0
- data/Gemfile +9 -3
- data/LICENSE +1 -1
- data/Pro-Changes.md +30 -0
- data/lib/sidekiq/api.rb +59 -27
- data/lib/sidekiq/cli.rb +13 -6
- data/lib/sidekiq/client.rb +31 -30
- data/lib/sidekiq/delay.rb +1 -0
- data/lib/sidekiq/fetch.rb +1 -1
- data/lib/sidekiq/job_logger.rb +2 -1
- data/lib/sidekiq/job_retry.rb +7 -2
- data/lib/sidekiq/launcher.rb +17 -11
- data/lib/sidekiq/logging.rb +3 -3
- data/lib/sidekiq/manager.rb +0 -1
- data/lib/sidekiq/middleware/server/active_record.rb +2 -1
- data/lib/sidekiq/processor.rb +55 -11
- data/lib/sidekiq/rails.rb +4 -9
- data/lib/sidekiq/redis_connection.rb +10 -2
- data/lib/sidekiq/scheduled.rb +33 -4
- data/lib/sidekiq/testing.rb +4 -4
- data/lib/sidekiq/util.rb +1 -1
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/action.rb +1 -1
- data/lib/sidekiq/web/application.rb +24 -2
- data/lib/sidekiq/web/helpers.rb +4 -4
- data/lib/sidekiq/web/router.rb +10 -10
- data/lib/sidekiq/web.rb +4 -4
- data/lib/sidekiq/worker.rb +7 -7
- data/lib/sidekiq.rb +4 -5
- data/sidekiq.gemspec +3 -8
- data/web/assets/javascripts/application.js +0 -0
- data/web/assets/stylesheets/application.css +0 -0
- data/web/assets/stylesheets/bootstrap.css +2 -2
- data/web/locales/ar.yml +1 -0
- data/web/locales/en.yml +1 -0
- data/web/locales/es.yml +3 -3
- data/web/views/_footer.erb +3 -0
- data/web/views/layout.erb +1 -1
- data/web/views/queue.erb +1 -0
- data/web/views/retries.erb +4 -0
- metadata +4 -87
- data/lib/sidekiq/middleware/server/active_record_cache.rb +0 -11
data/lib/sidekiq/launcher.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
require 'sidekiq/manager'
|
4
3
|
require 'sidekiq/fetch'
|
@@ -14,6 +13,8 @@ module Sidekiq
|
|
14
13
|
|
15
14
|
attr_accessor :manager, :poller, :fetcher
|
16
15
|
|
16
|
+
STATS_TTL = 5*365*24*60*60
|
17
|
+
|
17
18
|
def initialize(options)
|
18
19
|
@manager = Sidekiq::Manager.new(options)
|
19
20
|
@poller = Sidekiq::Scheduled::Poller.new
|
@@ -73,19 +74,24 @@ module Sidekiq
|
|
73
74
|
key = identity
|
74
75
|
fails = procd = 0
|
75
76
|
begin
|
76
|
-
Processor::FAILURE.
|
77
|
-
Processor::PROCESSED.
|
77
|
+
fails = Processor::FAILURE.reset
|
78
|
+
procd = Processor::PROCESSED.reset
|
79
|
+
curstate = Processor::WORKER_STATE.dup
|
78
80
|
|
79
|
-
workers_key = "#{key}:workers"
|
80
|
-
nowdate = Time.now.utc.strftime("%Y-%m-%d"
|
81
|
+
workers_key = "#{key}:workers"
|
82
|
+
nowdate = Time.now.utc.strftime("%Y-%m-%d")
|
81
83
|
Sidekiq.redis do |conn|
|
82
84
|
conn.multi do
|
83
|
-
conn.incrby("stat:processed"
|
85
|
+
conn.incrby("stat:processed", procd)
|
84
86
|
conn.incrby("stat:processed:#{nowdate}", procd)
|
85
|
-
conn.
|
87
|
+
conn.expire("stat:processed:#{nowdate}", STATS_TTL)
|
88
|
+
|
89
|
+
conn.incrby("stat:failed", fails)
|
86
90
|
conn.incrby("stat:failed:#{nowdate}", fails)
|
91
|
+
conn.expire("stat:failed:#{nowdate}", STATS_TTL)
|
92
|
+
|
87
93
|
conn.del(workers_key)
|
88
|
-
|
94
|
+
curstate.each_pair do |tid, hash|
|
89
95
|
conn.hset(workers_key, tid, Sidekiq.dump_json(hash))
|
90
96
|
end
|
91
97
|
conn.expire(workers_key, 60)
|
@@ -97,7 +103,7 @@ module Sidekiq
|
|
97
103
|
conn.multi do
|
98
104
|
conn.sadd('processes', key)
|
99
105
|
conn.exists(key)
|
100
|
-
conn.hmset(key, 'info', to_json, 'busy',
|
106
|
+
conn.hmset(key, 'info', to_json, 'busy', curstate.size, 'beat', Time.now.to_f, 'quiet', @done)
|
101
107
|
conn.expire(key, 60)
|
102
108
|
conn.rpop("#{key}-signals")
|
103
109
|
end
|
@@ -113,8 +119,8 @@ module Sidekiq
|
|
113
119
|
# ignore all redis/network issues
|
114
120
|
logger.error("heartbeat: #{e.message}")
|
115
121
|
# don't lose the counts if there was a network issue
|
116
|
-
Processor::PROCESSED.
|
117
|
-
Processor::FAILURE.
|
122
|
+
Processor::PROCESSED.incr(procd)
|
123
|
+
Processor::FAILURE.incr(fails)
|
118
124
|
end
|
119
125
|
end
|
120
126
|
|
data/lib/sidekiq/logging.rb
CHANGED
@@ -33,9 +33,9 @@ module Sidekiq
|
|
33
33
|
def self.job_hash_context(job_hash)
|
34
34
|
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
35
35
|
# attribute to expose the underlying thing.
|
36
|
-
klass = job_hash['wrapped'
|
37
|
-
bid = job_hash['bid'
|
38
|
-
"#{klass} JID-#{job_hash['jid'
|
36
|
+
klass = job_hash['wrapped'] || job_hash["class"]
|
37
|
+
bid = job_hash['bid']
|
38
|
+
"#{klass} JID-#{job_hash['jid']}#{" BID-#{bid}" if bid}"
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.with_job_hash_context(job_hash, &block)
|
data/lib/sidekiq/manager.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Sidekiq
|
2
3
|
module Middleware
|
3
4
|
module Server
|
@@ -6,7 +7,7 @@ module Sidekiq
|
|
6
7
|
def initialize
|
7
8
|
# With Rails 5+ we must use the Reloader **always**.
|
8
9
|
# The reloader handles code loading and db connection management.
|
9
|
-
if ::Rails::VERSION::MAJOR >= 5
|
10
|
+
if defined?(::Rails) && ::Rails::VERSION::MAJOR >= 5
|
10
11
|
raise ArgumentError, "Rails 5 no longer needs or uses the ActiveRecord middleware."
|
11
12
|
end
|
12
13
|
end
|
data/lib/sidekiq/processor.rb
CHANGED
@@ -4,8 +4,6 @@ require 'sidekiq/fetch'
|
|
4
4
|
require 'sidekiq/job_logger'
|
5
5
|
require 'sidekiq/job_retry'
|
6
6
|
require 'thread'
|
7
|
-
require 'concurrent/map'
|
8
|
-
require 'concurrent/atomic/atomic_fixnum'
|
9
7
|
|
10
8
|
module Sidekiq
|
11
9
|
##
|
@@ -132,9 +130,9 @@ module Sidekiq
|
|
132
130
|
# the Reloader. It handles code loading, db connection management, etc.
|
133
131
|
# Effectively this block denotes a "unit of work" to Rails.
|
134
132
|
@reloader.call do
|
135
|
-
klass = constantize(job_hash['class'
|
133
|
+
klass = constantize(job_hash['class'])
|
136
134
|
worker = klass.new
|
137
|
-
worker.jid = job_hash['jid'
|
135
|
+
worker.jid = job_hash['jid']
|
138
136
|
@retrier.local(worker, pristine, queue) do
|
139
137
|
yield worker
|
140
138
|
end
|
@@ -166,7 +164,7 @@ module Sidekiq
|
|
166
164
|
ack = true
|
167
165
|
dispatch(job_hash, queue) do |worker|
|
168
166
|
Sidekiq.server_middleware.invoke(worker, job_hash, queue) do
|
169
|
-
execute_job(worker, cloned(job_hash['args'
|
167
|
+
execute_job(worker, cloned(job_hash['args']))
|
170
168
|
end
|
171
169
|
end
|
172
170
|
rescue Sidekiq::Shutdown
|
@@ -187,22 +185,68 @@ module Sidekiq
|
|
187
185
|
worker.perform(*cloned_args)
|
188
186
|
end
|
189
187
|
|
190
|
-
|
191
|
-
|
192
|
-
|
188
|
+
# Ruby doesn't provide atomic counters out of the box so we'll
|
189
|
+
# implement something simple ourselves.
|
190
|
+
# https://bugs.ruby-lang.org/issues/14706
|
191
|
+
class Counter
|
192
|
+
def initialize
|
193
|
+
@value = 0
|
194
|
+
@lock = Mutex.new
|
195
|
+
end
|
196
|
+
|
197
|
+
def incr(amount=1)
|
198
|
+
@lock.synchronize { @value = @value + amount }
|
199
|
+
end
|
200
|
+
|
201
|
+
def reset
|
202
|
+
@lock.synchronize { val = @value; @value = 0; val }
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# jruby's Hash implementation is not threadsafe, so we wrap it in a mutex here
|
207
|
+
class SharedWorkerState
|
208
|
+
def initialize
|
209
|
+
@worker_state = {}
|
210
|
+
@lock = Mutex.new
|
211
|
+
end
|
212
|
+
|
213
|
+
def set(tid, hash)
|
214
|
+
@lock.synchronize { @worker_state[tid] = hash }
|
215
|
+
end
|
216
|
+
|
217
|
+
def delete(tid)
|
218
|
+
@lock.synchronize { @worker_state.delete(tid) }
|
219
|
+
end
|
220
|
+
|
221
|
+
def dup
|
222
|
+
@lock.synchronize { @worker_state.dup }
|
223
|
+
end
|
224
|
+
|
225
|
+
def size
|
226
|
+
@lock.synchronize { @worker_state.size }
|
227
|
+
end
|
228
|
+
|
229
|
+
def clear
|
230
|
+
@lock.synchronize { @worker_state.clear }
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
PROCESSED = Counter.new
|
235
|
+
FAILURE = Counter.new
|
236
|
+
WORKER_STATE = SharedWorkerState.new
|
193
237
|
|
194
238
|
def stats(job_hash, queue)
|
195
239
|
tid = Sidekiq::Logging.tid
|
196
|
-
WORKER_STATE
|
240
|
+
WORKER_STATE.set(tid, {:queue => queue, :payload => job_hash, :run_at => Time.now.to_i })
|
197
241
|
|
198
242
|
begin
|
199
243
|
yield
|
200
244
|
rescue Exception
|
201
|
-
FAILURE.
|
245
|
+
FAILURE.incr
|
202
246
|
raise
|
203
247
|
ensure
|
204
248
|
WORKER_STATE.delete(tid)
|
205
|
-
PROCESSED.
|
249
|
+
PROCESSED.incr
|
206
250
|
end
|
207
251
|
end
|
208
252
|
|
data/lib/sidekiq/rails.rb
CHANGED
@@ -9,15 +9,10 @@ module Sidekiq
|
|
9
9
|
# class block. Definitely before config/environments/*.rb and
|
10
10
|
# config/initializers/*.rb.
|
11
11
|
config.before_configuration do
|
12
|
-
if defined?(::ActiveRecord)
|
12
|
+
if ::Rails::VERSION::MAJOR < 5 && defined?(::ActiveRecord)
|
13
13
|
Sidekiq.server_middleware do |chain|
|
14
|
-
|
15
|
-
|
16
|
-
chain.add Sidekiq::Middleware::Server::ActiveRecord
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'sidekiq/middleware/server/active_record_cache'
|
20
|
-
chain.add Sidekiq::Middleware::Server::ActiveRecordCache
|
14
|
+
require 'sidekiq/middleware/server/active_record'
|
15
|
+
chain.add Sidekiq::Middleware::Server::ActiveRecord
|
21
16
|
end
|
22
17
|
end
|
23
18
|
end
|
@@ -59,4 +54,4 @@ if defined?(::Rails) && ::Rails::VERSION::MAJOR < 4
|
|
59
54
|
$stderr.puts("**************************************************")
|
60
55
|
$stderr.puts("⛔️ WARNING: Sidekiq server is no longer supported by Rails 3.2 - please ensure your server/workers are updated")
|
61
56
|
$stderr.puts("**************************************************")
|
62
|
-
end
|
57
|
+
end
|
@@ -15,7 +15,15 @@ module Sidekiq
|
|
15
15
|
options[:id] = "Sidekiq-#{Sidekiq.server? ? "server" : "client"}-PID-#{$$}" if !options.has_key?(:id)
|
16
16
|
options[:url] ||= determine_redis_provider
|
17
17
|
|
18
|
-
size = options[:size]
|
18
|
+
size = if options[:size]
|
19
|
+
options[:size]
|
20
|
+
elsif Sidekiq.server?
|
21
|
+
Sidekiq.options[:concurrency] + 5
|
22
|
+
elsif ENV['RAILS_MAX_THREADS']
|
23
|
+
Integer(ENV['RAILS_MAX_THREADS'])
|
24
|
+
else
|
25
|
+
5
|
26
|
+
end
|
19
27
|
|
20
28
|
verify_sizing(size, Sidekiq.options[:concurrency]) if Sidekiq.server?
|
21
29
|
|
@@ -70,7 +78,7 @@ module Sidekiq
|
|
70
78
|
opts.delete(:network_timeout)
|
71
79
|
end
|
72
80
|
|
73
|
-
opts[:driver] ||= 'ruby'
|
81
|
+
opts[:driver] ||= Redis::Connection.drivers.last || 'ruby'
|
74
82
|
|
75
83
|
# Issue #3303, redis-rb will silently retry an operation.
|
76
84
|
# This can lead to duplicate jobs if Sidekiq::Client's LPUSH
|
data/lib/sidekiq/scheduled.rb
CHANGED
@@ -17,7 +17,7 @@ module Sidekiq
|
|
17
17
|
# We need to go through the list one at a time to reduce the risk of something
|
18
18
|
# going wrong between the time jobs are popped from the scheduled queue and when
|
19
19
|
# they are pushed onto a work queue and losing the jobs.
|
20
|
-
while job = conn.zrangebyscore(sorted_set, '-inf'
|
20
|
+
while job = conn.zrangebyscore(sorted_set, '-inf', now, :limit => [0, 1]).first do
|
21
21
|
|
22
22
|
# Pop item off the queue and add it to the work queue. If the job can't be popped from
|
23
23
|
# the queue, it's because another process already popped it so we can move on to the
|
@@ -97,9 +97,34 @@ module Sidekiq
|
|
97
97
|
sleep 5
|
98
98
|
end
|
99
99
|
|
100
|
-
# Calculates a random interval that is ±50% the desired average.
|
101
100
|
def random_poll_interval
|
102
|
-
|
101
|
+
# We want one Sidekiq process to schedule jobs every N seconds. We have M processes
|
102
|
+
# and **don't** want to coordinate.
|
103
|
+
#
|
104
|
+
# So in N*M second timespan, we want each process to schedule once. The basic loop is:
|
105
|
+
#
|
106
|
+
# * sleep a random amount within that N*M timespan
|
107
|
+
# * wake up and schedule
|
108
|
+
#
|
109
|
+
# We want to avoid one edge case: imagine a set of 2 processes, scheduling every 5 seconds,
|
110
|
+
# so N*M = 10. Each process decides to randomly sleep 8 seconds, now we've failed to meet
|
111
|
+
# that 5 second average. Thankfully each schedule cycle will sleep randomly so the next
|
112
|
+
# iteration could see each process sleep for 1 second, undercutting our average.
|
113
|
+
#
|
114
|
+
# So below 10 processes, we special case and ensure the processes sleep closer to the average.
|
115
|
+
# In the example above, each process should schedule every 10 seconds on average. We special
|
116
|
+
# case smaller clusters to add 50% so they would sleep somewhere between 5 and 15 seconds.
|
117
|
+
# As we run more processes, the scheduling interval average will approach an even spread
|
118
|
+
# between 0 and poll interval so we don't need this artifical boost.
|
119
|
+
#
|
120
|
+
if process_count < 10
|
121
|
+
# For small clusters, calculate a random interval that is ±50% the desired average.
|
122
|
+
poll_interval_average * rand + poll_interval_average.to_f / 2
|
123
|
+
else
|
124
|
+
# With 10+ processes, we should have enough randomness to get decent polling
|
125
|
+
# across the entire timespan
|
126
|
+
poll_interval_average * rand
|
127
|
+
end
|
103
128
|
end
|
104
129
|
|
105
130
|
# We do our best to tune the poll interval to the size of the active Sidekiq
|
@@ -123,9 +148,13 @@ module Sidekiq
|
|
123
148
|
# This minimizes a single point of failure by dispersing check-ins but without taxing
|
124
149
|
# Redis if you run many Sidekiq processes.
|
125
150
|
def scaled_poll_interval
|
151
|
+
process_count * Sidekiq.options[:average_scheduled_poll_interval]
|
152
|
+
end
|
153
|
+
|
154
|
+
def process_count
|
126
155
|
pcount = Sidekiq::ProcessSet.new.size
|
127
156
|
pcount = 1 if pcount == 0
|
128
|
-
pcount
|
157
|
+
pcount
|
129
158
|
end
|
130
159
|
|
131
160
|
def initial_wait
|
data/lib/sidekiq/testing.rb
CHANGED
@@ -72,9 +72,7 @@ module Sidekiq
|
|
72
72
|
|
73
73
|
class EmptyQueueError < RuntimeError; end
|
74
74
|
|
75
|
-
|
76
|
-
alias_method :raw_push_real, :raw_push
|
77
|
-
|
75
|
+
module TestingClient
|
78
76
|
def raw_push(payloads)
|
79
77
|
if Sidekiq::Testing.fake?
|
80
78
|
payloads.each do |job|
|
@@ -92,11 +90,13 @@ module Sidekiq
|
|
92
90
|
end
|
93
91
|
true
|
94
92
|
else
|
95
|
-
|
93
|
+
super
|
96
94
|
end
|
97
95
|
end
|
98
96
|
end
|
99
97
|
|
98
|
+
Sidekiq::Client.prepend TestingClient
|
99
|
+
|
100
100
|
module Queues
|
101
101
|
##
|
102
102
|
# The Queues class is only for testing the fake queue implementation.
|
data/lib/sidekiq/util.rb
CHANGED
data/lib/sidekiq/version.rb
CHANGED
data/lib/sidekiq/web/action.rb
CHANGED
@@ -4,9 +4,24 @@ module Sidekiq
|
|
4
4
|
class WebApplication
|
5
5
|
extend WebRouter
|
6
6
|
|
7
|
-
CONTENT_LENGTH = "Content-Length"
|
8
|
-
CONTENT_TYPE = "Content-Type"
|
7
|
+
CONTENT_LENGTH = "Content-Length"
|
8
|
+
CONTENT_TYPE = "Content-Type"
|
9
9
|
REDIS_KEYS = %w(redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human)
|
10
|
+
CSP_HEADER = [
|
11
|
+
"default-src 'self' https: http:",
|
12
|
+
"child-src 'self'",
|
13
|
+
"connect-src 'self' https: http: wss: ws:",
|
14
|
+
"font-src 'self' https: http:",
|
15
|
+
"frame-src 'self'",
|
16
|
+
"img-src 'self' https: http: data:",
|
17
|
+
"manifest-src 'self'",
|
18
|
+
"media-src 'self'",
|
19
|
+
"object-src 'none'",
|
20
|
+
"script-src 'self' https: http:",
|
21
|
+
"style-src 'self' https: http: 'unsafe-inline'",
|
22
|
+
"worker-src 'self'",
|
23
|
+
"base-uri 'self'"
|
24
|
+
].join('; ').freeze
|
10
25
|
|
11
26
|
def initialize(klass)
|
12
27
|
@klass = klass
|
@@ -181,6 +196,12 @@ module Sidekiq
|
|
181
196
|
redirect "#{root_path}retries"
|
182
197
|
end
|
183
198
|
|
199
|
+
post "/retries/all/kill" do
|
200
|
+
Sidekiq::RetrySet.new.kill_all
|
201
|
+
|
202
|
+
redirect "#{root_path}retries"
|
203
|
+
end
|
204
|
+
|
184
205
|
post "/retries/:key" do
|
185
206
|
job = Sidekiq::RetrySet.new.fetch(*parse_params(route_params[:key])).first
|
186
207
|
|
@@ -279,6 +300,7 @@ module Sidekiq
|
|
279
300
|
"Content-Type" => "text/html",
|
280
301
|
"Cache-Control" => "no-cache",
|
281
302
|
"Content-Language" => action.locale,
|
303
|
+
"Content-Security-Policy" => CSP_HEADER
|
282
304
|
}
|
283
305
|
|
284
306
|
[200, headers, [resp]]
|
data/lib/sidekiq/web/helpers.rb
CHANGED
@@ -80,7 +80,7 @@ module Sidekiq
|
|
80
80
|
|
81
81
|
# See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
|
82
82
|
def user_preferred_languages
|
83
|
-
languages = env['HTTP_ACCEPT_LANGUAGE'
|
83
|
+
languages = env['HTTP_ACCEPT_LANGUAGE']
|
84
84
|
languages.to_s.downcase.gsub(/\s+/, '').split(',').map do |language|
|
85
85
|
locale, quality = language.split(';q=', 2)
|
86
86
|
locale = nil if locale == '*' # Ignore wildcards
|
@@ -121,7 +121,7 @@ module Sidekiq
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def t(msg, options={})
|
124
|
-
string = get_locale[msg] || msg
|
124
|
+
string = get_locale[msg] || strings('en')[msg] || msg
|
125
125
|
if options.empty?
|
126
126
|
string
|
127
127
|
else
|
@@ -155,7 +155,7 @@ module Sidekiq
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def namespace
|
158
|
-
|
158
|
+
@ns ||= Sidekiq.redis { |conn| conn.respond_to?(:namespace) ? conn.namespace : nil }
|
159
159
|
end
|
160
160
|
|
161
161
|
def redis_info
|
@@ -184,7 +184,7 @@ module Sidekiq
|
|
184
184
|
end
|
185
185
|
|
186
186
|
def parse_params(params)
|
187
|
-
score, jid = params.split("-")
|
187
|
+
score, jid = params.split("-", 2)
|
188
188
|
[score.to_f, jid]
|
189
189
|
end
|
190
190
|
|
data/lib/sidekiq/web/router.rb
CHANGED
@@ -3,16 +3,16 @@ require 'rack'
|
|
3
3
|
|
4
4
|
module Sidekiq
|
5
5
|
module WebRouter
|
6
|
-
GET = 'GET'
|
7
|
-
DELETE = 'DELETE'
|
8
|
-
POST = 'POST'
|
9
|
-
PUT = 'PUT'
|
10
|
-
PATCH = 'PATCH'
|
11
|
-
HEAD = 'HEAD'
|
6
|
+
GET = 'GET'
|
7
|
+
DELETE = 'DELETE'
|
8
|
+
POST = 'POST'
|
9
|
+
PUT = 'PUT'
|
10
|
+
PATCH = 'PATCH'
|
11
|
+
HEAD = 'HEAD'
|
12
12
|
|
13
|
-
ROUTE_PARAMS = 'rack.route_params'
|
14
|
-
REQUEST_METHOD = 'REQUEST_METHOD'
|
15
|
-
PATH_INFO = 'PATH_INFO'
|
13
|
+
ROUTE_PARAMS = 'rack.route_params'
|
14
|
+
REQUEST_METHOD = 'REQUEST_METHOD'
|
15
|
+
PATH_INFO = 'PATH_INFO'
|
16
16
|
|
17
17
|
def get(path, &block)
|
18
18
|
route(GET, path, &block)
|
@@ -64,7 +64,7 @@ module Sidekiq
|
|
64
64
|
class WebRoute
|
65
65
|
attr_accessor :request_method, :pattern, :block, :name
|
66
66
|
|
67
|
-
NAMED_SEGMENTS_PATTERN = /\/([^\/]*):([^\.:$\/]+)
|
67
|
+
NAMED_SEGMENTS_PATTERN = /\/([^\/]*):([^\.:$\/]+)/
|
68
68
|
|
69
69
|
def initialize(request_method, pattern, block)
|
70
70
|
@request_method = request_method
|
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"
|
23
|
-
LOCALES = ["#{ROOT}/locales"
|
24
|
-
LAYOUT = "#{VIEWS}/layout.erb"
|
25
|
-
ASSETS = "#{ROOT}/assets"
|
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" => '',
|
data/lib/sidekiq/worker.rb
CHANGED
@@ -47,7 +47,7 @@ module Sidekiq
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def perform_async(*args)
|
50
|
-
@klass.client_push(@opts.merge('args'
|
50
|
+
@klass.client_push(@opts.merge('args' => args, 'class' => @klass))
|
51
51
|
end
|
52
52
|
|
53
53
|
# +interval+ must be a timestamp, numeric or something that acts
|
@@ -57,9 +57,9 @@ module Sidekiq
|
|
57
57
|
now = Time.now.to_f
|
58
58
|
ts = (int < 1_000_000_000 ? now + int : int)
|
59
59
|
|
60
|
-
payload = @opts.merge('class'
|
60
|
+
payload = @opts.merge('class' => @klass, 'args' => args, 'at' => ts)
|
61
61
|
# Optimization to enqueue something now that is scheduled to go out now or in the past
|
62
|
-
payload.delete('at'
|
62
|
+
payload.delete('at') if ts <= now
|
63
63
|
@klass.client_push(payload)
|
64
64
|
end
|
65
65
|
alias_method :perform_at, :perform_in
|
@@ -84,7 +84,7 @@ module Sidekiq
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def perform_async(*args)
|
87
|
-
client_push('class'
|
87
|
+
client_push('class' => self, 'args' => args)
|
88
88
|
end
|
89
89
|
|
90
90
|
# +interval+ must be a timestamp, numeric or something that acts
|
@@ -94,10 +94,10 @@ module Sidekiq
|
|
94
94
|
now = Time.now.to_f
|
95
95
|
ts = (int < 1_000_000_000 ? now + int : int)
|
96
96
|
|
97
|
-
item = { 'class'
|
97
|
+
item = { 'class' => self, 'args' => args, 'at' => ts }
|
98
98
|
|
99
99
|
# Optimization to enqueue something now that is scheduled to go out now or in the past
|
100
|
-
item.delete('at'
|
100
|
+
item.delete('at') if ts <= now
|
101
101
|
|
102
102
|
client_push(item)
|
103
103
|
end
|
@@ -134,7 +134,7 @@ module Sidekiq
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def client_push(item) # :nodoc:
|
137
|
-
pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options['pool'
|
137
|
+
pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options['pool'] || Sidekiq.redis_pool
|
138
138
|
# stringify
|
139
139
|
item.keys.each do |key|
|
140
140
|
item[key.to_s] = item.delete(key)
|
data/lib/sidekiq.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
require 'sidekiq/version'
|
4
|
-
fail "Sidekiq #{Sidekiq::VERSION} does not support Ruby versions below 2.2.2." if RUBY_PLATFORM != 'java' && RUBY_VERSION < '2.2.2'
|
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'
|
@@ -12,13 +11,13 @@ require 'sidekiq/delay'
|
|
12
11
|
require 'json'
|
13
12
|
|
14
13
|
module Sidekiq
|
15
|
-
NAME = 'Sidekiq'
|
14
|
+
NAME = 'Sidekiq'
|
16
15
|
LICENSE = 'See LICENSE and the LGPL-3.0 for licensing details.'
|
17
16
|
|
18
17
|
DEFAULTS = {
|
19
18
|
queues: [],
|
20
19
|
labels: [],
|
21
|
-
concurrency:
|
20
|
+
concurrency: 10,
|
22
21
|
require: '.',
|
23
22
|
environment: nil,
|
24
23
|
timeout: 8,
|
@@ -48,7 +47,7 @@ module Sidekiq
|
|
48
47
|
"connected_clients" => "9999",
|
49
48
|
"used_memory_human" => "9P",
|
50
49
|
"used_memory_peak_human" => "9P"
|
51
|
-
}
|
50
|
+
}
|
52
51
|
|
53
52
|
def self.❨╯°□°❩╯︵┻━┻
|
54
53
|
puts "Calm down, yo."
|
data/sidekiq.gemspec
CHANGED
@@ -17,12 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.version = Sidekiq::VERSION
|
18
18
|
gem.required_ruby_version = ">= 2.2.2"
|
19
19
|
|
20
|
-
gem.add_dependency
|
21
|
-
gem.add_dependency
|
22
|
-
gem.add_dependency
|
23
|
-
gem.add_dependency 'rack-protection', '>= 1.5.0'
|
24
|
-
gem.add_development_dependency 'redis-namespace', '~> 1.5', '>= 1.5.2'
|
25
|
-
gem.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.1'
|
26
|
-
gem.add_development_dependency 'rake', '~> 10.0'
|
27
|
-
gem.add_development_dependency 'rails', '>= 3.2.0'
|
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'
|
28
23
|
end
|
File without changes
|
File without changes
|