sidekiq 2.10.0 → 2.10.1
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.
- data/Changes.md +10 -0
- data/README.md +1 -1
- data/lib/sidekiq/api.rb +9 -1
- data/lib/sidekiq/cli.rb +1 -1
- data/lib/sidekiq/redis_connection.rb +39 -23
- data/lib/sidekiq/scheduled.rb +1 -1
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web.rb +22 -10
- data/sidekiq.gemspec +2 -3
- data/test/helper.rb +3 -1
- data/test/test_api.rb +17 -1
- data/test/test_fetch.rb +34 -33
- data/test/test_redis_connection.rb +1 -1
- data/web/locales/en.yml +1 -0
- data/web/views/_nav.slim +4 -0
- metadata +4 -20
data/Changes.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2.10.1
|
2
|
+
-----------
|
3
|
+
|
4
|
+
- Remove need for the i18n gem. (brandonhilkert)
|
5
|
+
- Improve redis connection info logging on startup for debugging
|
6
|
+
purposes [#858]
|
7
|
+
- Revert sinatra/slim as runtime dependencies
|
8
|
+
- Add `find_job` method to sidekiq/api
|
9
|
+
|
10
|
+
|
1
11
|
2.10.0
|
2
12
|
-----------
|
3
13
|
|
data/README.md
CHANGED
@@ -78,7 +78,7 @@ The mailing list is the preferred place to ask questions on usage. If you are en
|
|
78
78
|
License
|
79
79
|
-----------------
|
80
80
|
|
81
|
-
Please see LICENSE for licensing details.
|
81
|
+
Please see [LICENSE](https://github.com/mperham/sidekiq/blob/master/LICENSE) for licensing details.
|
82
82
|
|
83
83
|
|
84
84
|
Author
|
data/lib/sidekiq/api.rb
CHANGED
@@ -137,6 +137,10 @@ module Sidekiq
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
def find_job(jid)
|
141
|
+
self.detect { |j| j.jid == jid }
|
142
|
+
end
|
143
|
+
|
140
144
|
def clear
|
141
145
|
Sidekiq.redis do |conn|
|
142
146
|
conn.multi do
|
@@ -223,7 +227,7 @@ module Sidekiq
|
|
223
227
|
results.map do |message|
|
224
228
|
msg = Sidekiq.load_json(message)
|
225
229
|
msg['retry_count'] = msg['retry_count'] - 1
|
226
|
-
conn.
|
230
|
+
conn.lpush("queue:#{msg['queue']}", Sidekiq.dump_json(msg))
|
227
231
|
end
|
228
232
|
end
|
229
233
|
end
|
@@ -279,6 +283,10 @@ module Sidekiq
|
|
279
283
|
end
|
280
284
|
end
|
281
285
|
|
286
|
+
def find_job(jid)
|
287
|
+
self.detect { |j| j.jid == jid }
|
288
|
+
end
|
289
|
+
|
282
290
|
def delete(score, jid = nil)
|
283
291
|
if jid
|
284
292
|
elements = Sidekiq.redis do |conn|
|
data/lib/sidekiq/cli.rb
CHANGED
@@ -3,33 +3,49 @@ require 'redis'
|
|
3
3
|
|
4
4
|
module Sidekiq
|
5
5
|
class RedisConnection
|
6
|
-
|
7
|
-
url = options[:url] || determine_redis_provider || 'redis://localhost:6379/0'
|
8
|
-
# need a connection for Fetcher and Retry
|
9
|
-
size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 2) : 5)
|
6
|
+
class << self
|
10
7
|
|
11
|
-
|
12
|
-
|
8
|
+
def create(options={})
|
9
|
+
url = options[:url] || determine_redis_provider || 'redis://localhost:6379/0'
|
10
|
+
# need a connection for Fetcher and Retry
|
11
|
+
size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 2) : 5)
|
12
|
+
|
13
|
+
log_info(url, options)
|
14
|
+
|
15
|
+
ConnectionPool.new(:timeout => 1, :size => size) do
|
16
|
+
build_client(url, options[:namespace], options[:driver] || 'ruby')
|
17
|
+
end
|
13
18
|
end
|
14
|
-
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
private
|
21
|
+
|
22
|
+
def build_client(url, namespace, driver)
|
23
|
+
client = Redis.connect(:url => url, :driver => driver)
|
24
|
+
if namespace
|
25
|
+
require 'redis/namespace'
|
26
|
+
Redis::Namespace.new(namespace, :redis => client)
|
27
|
+
else
|
28
|
+
client
|
29
|
+
end
|
23
30
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
|
32
|
+
def log_info(url, options)
|
33
|
+
opts = options.dup
|
34
|
+
opts.delete(:url)
|
35
|
+
if Sidekiq.server?
|
36
|
+
Sidekiq.logger.info("Booting #{Sidekiq::NAME} #{Sidekiq::VERSION} using #{url} with options #{opts}")
|
37
|
+
else
|
38
|
+
Sidekiq.logger.info("#{Sidekiq::NAME} client using #{url} with options #{opts}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def determine_redis_provider
|
43
|
+
# REDISTOGO_URL is only support for legacy reasons
|
44
|
+
return ENV['REDISTOGO_URL'] if ENV['REDISTOGO_URL']
|
45
|
+
provider = ENV['REDIS_PROVIDER'] || 'REDIS_URL'
|
46
|
+
ENV[provider]
|
47
|
+
end
|
48
|
+
|
33
49
|
end
|
34
50
|
end
|
35
51
|
end
|
data/lib/sidekiq/scheduled.rb
CHANGED
@@ -40,7 +40,7 @@ module Sidekiq
|
|
40
40
|
if conn.zrem(sorted_set, message)
|
41
41
|
conn.multi do
|
42
42
|
conn.sadd('queues', msg['queue'])
|
43
|
-
conn.
|
43
|
+
conn.lpush("queue:#{msg['queue']}", message)
|
44
44
|
end
|
45
45
|
logger.debug("enqueued #{sorted_set}: #{message}") if logger.debug?
|
46
46
|
end
|
data/lib/sidekiq/version.rb
CHANGED
data/lib/sidekiq/web.rb
CHANGED
@@ -1,27 +1,35 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'slim'
|
3
3
|
require 'sidekiq/paginator'
|
4
|
-
require 'i18n'
|
5
4
|
|
6
5
|
module Sidekiq
|
7
6
|
class Web < Sinatra::Base
|
8
7
|
include Sidekiq::Paginator
|
9
8
|
|
10
9
|
dir = File.expand_path(File.dirname(__FILE__) + "/../../web")
|
11
|
-
I18n.load_path += Dir[File.join(dir, 'locales', '*.yml').to_s]
|
12
10
|
|
13
11
|
set :public_folder, "#{dir}/assets"
|
14
12
|
set :views, "#{dir}/views"
|
15
13
|
set :root, "#{dir}/public"
|
14
|
+
set :locales, "#{dir}/locales"
|
16
15
|
set :slim, :pretty => true
|
17
16
|
|
18
17
|
helpers do
|
18
|
+
def strings
|
19
|
+
@strings ||= begin
|
20
|
+
Dir["#{settings.locales}/*.yml"].inject({}) do |memo, file|
|
21
|
+
memo.merge(YAML.load(File.read(file)))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
def get_locale
|
20
27
|
(request.env["HTTP_ACCEPT_LANGUAGE"] || 'en')[0,2]
|
21
28
|
end
|
22
29
|
|
23
30
|
def t(msg, options={})
|
24
|
-
|
31
|
+
string = strings[get_locale].fetch(msg) || strings['en'].fetch(msg)
|
32
|
+
string % options
|
25
33
|
end
|
26
34
|
|
27
35
|
def reset_worker_list
|
@@ -94,6 +102,16 @@ module Sidekiq
|
|
94
102
|
end
|
95
103
|
|
96
104
|
def tabs
|
105
|
+
@tabs ||= {
|
106
|
+
"Dashboard" => '',
|
107
|
+
"Workers" => 'workers',
|
108
|
+
"Queues" => 'queues',
|
109
|
+
"Retries" => 'retries',
|
110
|
+
"Scheduled" => 'scheduled',
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def custom_tabs
|
97
115
|
self.class.tabs
|
98
116
|
end
|
99
117
|
|
@@ -240,13 +258,7 @@ module Sidekiq
|
|
240
258
|
end
|
241
259
|
|
242
260
|
def self.tabs
|
243
|
-
@
|
244
|
-
"Dashboard" => '',
|
245
|
-
"Workers" => 'workers',
|
246
|
-
"Queues" => 'queues',
|
247
|
-
"Retries" => 'retries',
|
248
|
-
"Scheduled" => 'scheduled',
|
249
|
-
}
|
261
|
+
@custom_tabs ||= {}
|
250
262
|
end
|
251
263
|
|
252
264
|
end
|
data/sidekiq.gemspec
CHANGED
@@ -19,9 +19,8 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_dependency 'connection_pool', '~> 1.0'
|
20
20
|
gem.add_dependency 'celluloid', '~> 0.12.0'
|
21
21
|
gem.add_dependency 'multi_json', '~> 1'
|
22
|
-
gem.
|
23
|
-
gem.
|
24
|
-
gem.add_dependency 'i18n'
|
22
|
+
gem.add_development_dependency 'sinatra'
|
23
|
+
gem.add_development_dependency 'slim'
|
25
24
|
gem.add_development_dependency 'minitest', '~> 4'
|
26
25
|
gem.add_development_dependency 'rake'
|
27
26
|
gem.add_development_dependency 'actionmailer', '~> 3'
|
data/test/helper.rb
CHANGED
data/test/test_api.rb
CHANGED
@@ -179,6 +179,22 @@ class TestApi < MiniTest::Unit::TestCase
|
|
179
179
|
assert_equal 0, q.size
|
180
180
|
end
|
181
181
|
|
182
|
+
it 'can find job by id in sorted sets' do
|
183
|
+
q = Sidekiq::Queue.new
|
184
|
+
job_id = ApiWorker.perform_in(100, 1, 'jason')
|
185
|
+
job = Sidekiq::ScheduledSet.new.find_job(job_id)
|
186
|
+
refute_nil job
|
187
|
+
assert_equal job_id, job.jid
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'can find job by id in queues' do
|
191
|
+
q = Sidekiq::Queue.new
|
192
|
+
job_id = ApiWorker.perform_async(1, 'jason')
|
193
|
+
job = q.find_job(job_id)
|
194
|
+
refute_nil job
|
195
|
+
assert_equal job_id, job.jid
|
196
|
+
end
|
197
|
+
|
182
198
|
it 'can clear a queue' do
|
183
199
|
q = Sidekiq::Queue.new
|
184
200
|
2.times { ApiWorker.perform_async(1, 'mike') }
|
@@ -278,7 +294,7 @@ class TestApi < MiniTest::Unit::TestCase
|
|
278
294
|
|
279
295
|
s = '12345'
|
280
296
|
data = Sidekiq.dump_json({ 'payload' => {}, 'queue' => 'default', 'run_at' => Time.now.to_i })
|
281
|
-
Sidekiq.redis do |c|
|
297
|
+
Sidekiq.redis do |c|
|
282
298
|
c.multi do
|
283
299
|
c.sadd('workers', s)
|
284
300
|
c.set("worker:#{s}", data)
|
data/test/test_fetch.rb
CHANGED
@@ -2,42 +2,43 @@ require 'helper'
|
|
2
2
|
require 'sidekiq/fetch'
|
3
3
|
|
4
4
|
class TestFetcher < MiniTest::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe 'fetcher' do
|
6
|
+
before do
|
7
|
+
Sidekiq.redis = { :namespace => 'fuzzy' }
|
8
|
+
Sidekiq.redis do |conn|
|
9
|
+
conn.flushdb
|
10
|
+
conn.rpush('queue:basic', 'msg')
|
11
|
+
end
|
11
12
|
end
|
12
|
-
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
it 'retrieves' do
|
15
|
+
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar'])
|
16
|
+
uow = fetch.retrieve_work
|
17
|
+
refute_nil uow
|
18
|
+
assert_equal 'basic', uow.queue_name
|
19
|
+
assert_equal 'msg', uow.message
|
20
|
+
q = Sidekiq::Queue.new('basic')
|
21
|
+
assert_equal 0, q.size
|
22
|
+
uow.requeue
|
23
|
+
assert_equal 1, q.size
|
24
|
+
assert_nil uow.acknowledge
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
it 'retrieves with strict setting' do
|
28
|
+
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar', 'bar'], :strict => true)
|
29
|
+
cmd = fetch.queues_cmd
|
30
|
+
assert_equal cmd, ['queue:basic', 'queue:bar', 1]
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
it 'bulk requeues' do
|
34
|
+
q1 = Sidekiq::Queue.new('foo')
|
35
|
+
q2 = Sidekiq::Queue.new('bar')
|
36
|
+
assert_equal 0, q1.size
|
37
|
+
assert_equal 0, q2.size
|
38
|
+
uow = Sidekiq::BasicFetch::UnitOfWork
|
39
|
+
Sidekiq::BasicFetch.bulk_requeue([uow.new('fuzzy:queue:foo', 'bob'), uow.new('fuzzy:queue:foo', 'bar'), uow.new('fuzzy:queue:bar', 'widget')])
|
40
|
+
assert_equal 2, q1.size
|
41
|
+
assert_equal 1, q2.size
|
42
|
+
end
|
42
43
|
end
|
43
44
|
end
|
@@ -33,7 +33,7 @@ class TestRedisConnection < MiniTest::Unit::TestCase
|
|
33
33
|
ENV[v] = nil
|
34
34
|
end
|
35
35
|
ENV[var] = uri
|
36
|
-
assert_equal uri, Sidekiq::RedisConnection.determine_redis_provider
|
36
|
+
assert_equal uri, Sidekiq::RedisConnection.send(:determine_redis_provider)
|
37
37
|
ENV[var] = nil
|
38
38
|
end
|
39
39
|
|
data/web/locales/en.yml
CHANGED
data/web/views/_nav.slim
CHANGED
@@ -10,3 +10,7 @@
|
|
10
10
|
- else
|
11
11
|
li class="#{(current_path =~ Regexp.new(url)) ? 'active':''}"
|
12
12
|
a href='#{{root_path}}#{{url}}' = t(title)
|
13
|
+
|
14
|
+
- custom_tabs.each do |title, url|
|
15
|
+
li class="#{(current_path =~ Regexp.new(url)) ? 'active':''}"
|
16
|
+
a href='#{{root_path}}#{{url}}' = title
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.10.
|
4
|
+
version: 2.10.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
|
-
type: :
|
102
|
+
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
@@ -115,23 +115,7 @@ dependencies:
|
|
115
115
|
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
|
-
type: :
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: i18n
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ! '>='
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '0'
|
134
|
-
type: :runtime
|
118
|
+
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
121
|
none: false
|