sidekiq 2.1.1 → 2.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.
- data/Changes.md +14 -0
- data/Gemfile +1 -1
- data/README.md +6 -2
- data/lib/sidekiq.rb +1 -0
- data/lib/sidekiq/cli.rb +2 -2
- data/lib/sidekiq/client.rb +4 -1
- data/lib/sidekiq/exception_handler.rb +1 -1
- data/lib/sidekiq/extensions/active_record.rb +5 -2
- data/lib/sidekiq/extensions/class_methods.rb +33 -0
- data/lib/sidekiq/processor.rb +16 -11
- data/lib/sidekiq/rails.rb +0 -1
- data/lib/sidekiq/scheduled.rb +1 -1
- data/lib/sidekiq/version.rb +1 -1
- data/test/test_cli.rb +5 -0
- data/test/test_client.rb +1 -0
- data/test/test_exception_handler.rb +4 -1
- data/test/test_extensions.rb +9 -0
- data/test/test_scheduling.rb +2 -2
- data/test/test_testing.rb +8 -3
- metadata +3 -2
data/Changes.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
2.2.0
|
2
|
+
-----------
|
3
|
+
|
4
|
+
- Add extension to delay any arbitrary class method to Sidekiq.
|
5
|
+
Previously this was limited to ActiveRecord classes.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
SomeClass.delay.class_method(1, 'mike', Date.today)
|
9
|
+
```
|
10
|
+
|
11
|
+
- Sidekiq::Client now generates and returns a random, 128-bit Job ID 'jid' which
|
12
|
+
can be used to track the processing of a Job, e.g. for calling back to a webhook
|
13
|
+
when a job is finished.
|
14
|
+
|
1
15
|
2.1.1
|
2
16
|
-----------
|
3
17
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
Sidekiq
|
1
|
+
Sidekiq
|
2
2
|
==============
|
3
3
|
|
4
|
+
[![Build Status](https://secure.travis-ci.org/mperham/sidekiq.png)](http://travis-ci.org/mperham/sidekiq)
|
5
|
+
[![Dependency Status](https://gemnasium.com/mperham/sidekiq.png)](https://gemnasium.com/mperham/sidekiq)
|
6
|
+
|
4
7
|
Simple, efficient message processing for Ruby.
|
5
8
|
|
6
9
|
Sidekiq uses threads to handle many messages at the same time in the
|
@@ -60,7 +63,8 @@ Problems?
|
|
60
63
|
|
61
64
|
**Please do not directly email any Sidekiq committers with questions or problems.** A community is best served when discussions are held in public.
|
62
65
|
|
63
|
-
If you have a problem, please review the [FAQ](/mperham/sidekiq/wiki/FAQ) and [Troubleshooting](/mperham/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages.
|
66
|
+
If you have a problem, please review the [FAQ](/mperham/sidekiq/wiki/FAQ) and [Troubleshooting](/mperham/sidekiq/wiki/Problems-and-Troubleshooting) wiki pages. Searching the issues for your problem is also a good idea. If that doesn't help, feel free to email the Sidekiq mailing list or open a new issue.
|
67
|
+
The mailing list is the preferred place to ask questions on usage. If you are encountering what you think is a bug, please open an issue.
|
64
68
|
|
65
69
|
|
66
70
|
License
|
data/lib/sidekiq.rb
CHANGED
@@ -5,6 +5,7 @@ require 'sidekiq/worker'
|
|
5
5
|
require 'sidekiq/redis_connection'
|
6
6
|
require 'sidekiq/util'
|
7
7
|
|
8
|
+
require 'sidekiq/extensions/class_methods'
|
8
9
|
require 'sidekiq/extensions/action_mailer'
|
9
10
|
require 'sidekiq/extensions/active_record'
|
10
11
|
require 'sidekiq/rails' if defined?(::Rails::Engine)
|
data/lib/sidekiq/cli.rb
CHANGED
@@ -58,7 +58,7 @@ module Sidekiq
|
|
58
58
|
options.merge!(config.merge(cli))
|
59
59
|
|
60
60
|
Sidekiq.logger.level = Logger::DEBUG if options[:verbose]
|
61
|
-
Celluloid.logger = nil
|
61
|
+
Celluloid.logger = nil unless options[:verbose]
|
62
62
|
|
63
63
|
validate!
|
64
64
|
write_pid
|
@@ -141,7 +141,7 @@ module Sidekiq
|
|
141
141
|
|
142
142
|
@parser = OptionParser.new do |o|
|
143
143
|
o.on "-q", "--queue QUEUE[,WEIGHT]...", "Queues to process with optional weights" do |arg|
|
144
|
-
queues_and_weights = arg.scan(/(\w+),?(\d*)/)
|
144
|
+
queues_and_weights = arg.scan(/([\w-]+),?(\d*)/)
|
145
145
|
queues_and_weights.each {|queue_and_weight| parse_queues(opts, *queue_and_weight)}
|
146
146
|
opts[:strict] = queues_and_weights.collect(&:last).none? {|weight| weight != ''}
|
147
147
|
end
|
data/lib/sidekiq/client.rb
CHANGED
@@ -28,6 +28,8 @@ module Sidekiq
|
|
28
28
|
# All options must be strings, not symbols. NB: because we are serializing to JSON, all
|
29
29
|
# symbols in 'args' will be converted to strings.
|
30
30
|
#
|
31
|
+
# Returns nil if not pushed to Redis or a unique Job ID if pushed.
|
32
|
+
#
|
31
33
|
# Example:
|
32
34
|
# Sidekiq::Client.push('queue' => 'my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar'])
|
33
35
|
#
|
@@ -42,6 +44,7 @@ module Sidekiq
|
|
42
44
|
item = worker_class.get_sidekiq_options.merge(item)
|
43
45
|
item['retry'] = !!item['retry']
|
44
46
|
queue = item['queue']
|
47
|
+
item['jid'] = SecureRandom.base64
|
45
48
|
|
46
49
|
pushed = false
|
47
50
|
Sidekiq.client_middleware.invoke(worker_class, item, queue) do
|
@@ -57,7 +60,7 @@ module Sidekiq
|
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
60
|
-
|
63
|
+
pushed ? item['jid'] : nil
|
61
64
|
end
|
62
65
|
|
63
66
|
# Redis compatibility helper. Example usage:
|
@@ -24,7 +24,7 @@ module Sidekiq
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def send_to_exception_notifier(msg, ex)
|
27
|
-
::ExceptionNotifier::Notifier.background_exception_notification(ex, :data => { :message => msg })
|
27
|
+
::ExceptionNotifier::Notifier.background_exception_notification(ex, :data => { :message => msg }).deliver
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -3,11 +3,14 @@ require 'sidekiq/extensions/generic_proxy'
|
|
3
3
|
module Sidekiq
|
4
4
|
module Extensions
|
5
5
|
##
|
6
|
-
# Adds a 'delay' method to
|
6
|
+
# Adds a 'delay' method to ActiveRecords to offload instance method
|
7
7
|
# execution to Sidekiq. Examples:
|
8
8
|
#
|
9
|
-
# User.delay.delete_inactive
|
10
9
|
# User.recent_signups.each { |user| user.delay.mark_as_awesome }
|
10
|
+
#
|
11
|
+
# Please note, this is not recommended as this will serialize the entire
|
12
|
+
# object to Redis. Your Sidekiq jobs should pass IDs, not entire instances.
|
13
|
+
# This is here for backwards compatibility with Delayed::Job only.
|
11
14
|
class DelayedModel
|
12
15
|
include Sidekiq::Worker
|
13
16
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sidekiq/extensions/generic_proxy'
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Extensions
|
5
|
+
##
|
6
|
+
# Adds a 'delay' method to all Classes to offload class method
|
7
|
+
# execution to Sidekiq. Examples:
|
8
|
+
#
|
9
|
+
# User.delay.delete_inactive
|
10
|
+
# Wikipedia.delay.download_changes_for(Date.today)
|
11
|
+
#
|
12
|
+
class DelayedClass
|
13
|
+
include Sidekiq::Worker
|
14
|
+
|
15
|
+
def perform(yml)
|
16
|
+
(target, method_name, args) = YAML.load(yml)
|
17
|
+
target.send(method_name, *args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Klass
|
22
|
+
def delay
|
23
|
+
Proxy.new(DelayedClass, self)
|
24
|
+
end
|
25
|
+
def delay_for(interval)
|
26
|
+
Proxy.new(DelayedClass, self, Time.now.to_f + interval.to_f)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Class.send(:include, Sidekiq::Extensions::Klass)
|
data/lib/sidekiq/processor.rb
CHANGED
@@ -15,8 +15,6 @@ module Sidekiq
|
|
15
15
|
include Util
|
16
16
|
include Celluloid
|
17
17
|
|
18
|
-
exclusive :process
|
19
|
-
|
20
18
|
def self.default_middleware
|
21
19
|
Middleware::Chain.new do |m|
|
22
20
|
m.add Middleware::Server::Logging
|
@@ -31,19 +29,26 @@ module Sidekiq
|
|
31
29
|
end
|
32
30
|
|
33
31
|
def process(msgstr, queue)
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
# Defer worker execution to Celluloid's thread pool since all actor
|
33
|
+
# invocations are run within a Fiber, which dramatically limits
|
34
|
+
# our stack size.
|
35
|
+
defer do
|
36
|
+
begin
|
37
|
+
msg = Sidekiq.load_json(msgstr)
|
38
|
+
klass = constantize(msg['class'])
|
39
|
+
worker = klass.new
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
stats(worker, msg, queue) do
|
42
|
+
Sidekiq.server_middleware.invoke(worker, msg, queue) do
|
43
|
+
worker.perform(*cloned(msg['args']))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
rescue => ex
|
47
|
+
handle_exception(ex, msg || { :message => msgstr })
|
48
|
+
raise
|
41
49
|
end
|
42
50
|
end
|
43
51
|
@boss.processor_done!(current_actor)
|
44
|
-
rescue => ex
|
45
|
-
handle_exception(ex, msg || { :message => msgstr })
|
46
|
-
raise
|
47
52
|
end
|
48
53
|
|
49
54
|
# See http://github.com/tarcieri/celluloid/issues/22
|
data/lib/sidekiq/rails.rb
CHANGED
data/lib/sidekiq/scheduled.rb
CHANGED
@@ -43,7 +43,7 @@ module Sidekiq
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
rescue SystemCallError => ex
|
46
|
+
rescue SystemCallError, Redis::TimeoutError, Redis::ConnectionError => ex
|
47
47
|
# ECONNREFUSED, etc. Most likely a problem with
|
48
48
|
# redis networking. Punt and try again at the next interval
|
49
49
|
logger.warn ex.message
|
data/lib/sidekiq/version.rb
CHANGED
data/test/test_cli.rb
CHANGED
@@ -65,6 +65,11 @@ class TestCli < MiniTest::Unit::TestCase
|
|
65
65
|
assert_equal %w(bar foo foo foo), Sidekiq.options[:queues]
|
66
66
|
end
|
67
67
|
|
68
|
+
it 'handles queues with multi-word names' do
|
69
|
+
@cli.parse(['sidekiq', '-q', 'queue_one,queue-two', '-r', './test/fake_env.rb'])
|
70
|
+
assert_equal %w(queue_one queue-two), Sidekiq.options[:queues]
|
71
|
+
end
|
72
|
+
|
68
73
|
it 'sets verbose' do
|
69
74
|
old = Sidekiq.logger.level
|
70
75
|
@cli.parse(['sidekiq', '-v', '-r', './test/fake_env.rb'])
|
data/test/test_client.rb
CHANGED
@@ -66,9 +66,12 @@ class TestExceptionHandler < MiniTest::Unit::TestCase
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "notifies ExceptionNotifier" do
|
69
|
-
::
|
69
|
+
mail = MiniTest::Mock.new
|
70
|
+
mail.expect(:deliver,nil)
|
71
|
+
::ExceptionNotifier::Notifier.expect(:background_exception_notification,mail,[TEST_EXCEPTION, :data => { :message => { :b => 2 } }])
|
70
72
|
Component.new.invoke_exception(:b => 2)
|
71
73
|
::ExceptionNotifier::Notifier.verify
|
74
|
+
mail.verify
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
data/test/test_extensions.rb
CHANGED
@@ -54,6 +54,15 @@ class TestExtensions < MiniTest::Unit::TestCase
|
|
54
54
|
UserMailer.delay_for(5.days).greetings(1, 2)
|
55
55
|
assert_equal 1, Sidekiq.redis {|c| c.zcard('schedule') }
|
56
56
|
end
|
57
|
+
|
58
|
+
class SomeClass
|
59
|
+
def self.doit(arg)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'allows delay of any ole class method' do
|
64
|
+
SomeClass.delay.doit(Date.today)
|
65
|
+
end
|
57
66
|
end
|
58
67
|
|
59
68
|
describe 'sidekiq rails extensions configuration' do
|
data/test/test_scheduling.rb
CHANGED
@@ -19,13 +19,13 @@ class TestScheduling < MiniTest::Unit::TestCase
|
|
19
19
|
|
20
20
|
it 'schedules a job via interval' do
|
21
21
|
@redis.expect :zadd, true, ['schedule', String, String]
|
22
|
-
|
22
|
+
assert ScheduledWorker.perform_in(600, 'mike')
|
23
23
|
@redis.verify
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'schedules a job via timestamp' do
|
27
27
|
@redis.expect :zadd, true, ['schedule', String, String]
|
28
|
-
|
28
|
+
assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
|
29
29
|
@redis.verify
|
30
30
|
end
|
31
31
|
end
|
data/test/test_testing.rb
CHANGED
@@ -76,10 +76,15 @@ class TestTesting < MiniTest::Unit::TestCase
|
|
76
76
|
assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
|
77
77
|
end
|
78
78
|
|
79
|
+
class Something
|
80
|
+
def self.foo(x)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
79
84
|
it 'stubs the delay call on models' do
|
80
|
-
assert_equal 0, Sidekiq::Extensions::
|
81
|
-
|
82
|
-
assert_equal 1, Sidekiq::Extensions::
|
85
|
+
assert_equal 0, Sidekiq::Extensions::DelayedClass.jobs.size
|
86
|
+
Something.delay.foo(Date.today)
|
87
|
+
assert_equal 1, Sidekiq::Extensions::DelayedClass.jobs.size
|
83
88
|
end
|
84
89
|
|
85
90
|
it 'stubs the enqueue call' do
|
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.
|
4
|
+
version: 2.2.0
|
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: 2012-08-
|
12
|
+
date: 2012-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -229,6 +229,7 @@ files:
|
|
229
229
|
- lib/sidekiq/exception_handler.rb
|
230
230
|
- lib/sidekiq/extensions/action_mailer.rb
|
231
231
|
- lib/sidekiq/extensions/active_record.rb
|
232
|
+
- lib/sidekiq/extensions/class_methods.rb
|
232
233
|
- lib/sidekiq/extensions/generic_proxy.rb
|
233
234
|
- lib/sidekiq/fetch.rb
|
234
235
|
- lib/sidekiq/logging.rb
|