sidekiq 2.3.3 → 2.4.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.

@@ -0,0 +1,83 @@
1
+ THIS LICENSE AGREEMENT DESCRIBES YOUR RIGHTS WITH RESPECT TO THE SOFTWARE AND ITS COMPONENTS.
2
+
3
+ 1. OWNERSHIP, LICENSE GRANT
4
+
5
+ This is a license agreement and not an agreement for sale. We reserve ownership of all intellectual property rights inherent in or relating to the Software, which include, but are not limited to, all copyright, patent rights, all rights in relation to registered and unregistered trademarks (including service marks), confidential information (including trade secrets and know-how) and all rights other than those expressly granted by this License Agreement.
6
+
7
+ Subject to the payment of the fee required and subject to the terms and conditions of this License Agreement, We grant to You a revocable, non- transferable and non-exclusive license (i) for Designated User(s) (as defined below) within Your organization to install and use the Software on any workstations used exclusively by such Designated User and (ii) for You to install and use the Software in connection with unlimited domains and sub-domains on unlimited servers, solely in connection with distribution of the Software in accordance with sections 3 and 4 below. This license is not sublicensable except as explicitly set forth herein. “Designated User(s)” shall mean Your employee(s) acting within the scope of their employment or Your consultant(s) or contractor(s) acting within the scope of the services they provide for You or on Your behalf for whom You have purchased a license to use the Software.
8
+
9
+ In addition to the other terms contained herein, We grant to You a revocable, non- transferable and non-exclusive license to install and use the Software on a single computer (the “Trial License”) strictly for Your internal evaluation and review purposes and not for production purposes. This Trial License applies only if You have registered with Us for a Trial License of the Software and shall be effective for forty-five (45) consecutive days following the date of registration (“the Trial Period”). You may only register for a Trial License once in any eighteen month period. You agree not to use a Trial License for any purpose other than determining whether to purchase a license to the Software. You are explicitly not permitted to distribute the Software to any user outside the Organization on whose behalf you have undertaken this license. Your rights to use the Trial License will immediately terminate upon the earlier of (i) the expiration of the Trial Period, or (ii) such time that You purchase a license to the Software. We reserve the right to terminate Your Trial License at any time in Our absolute and sole discretion.
10
+
11
+ 2. PERMITTED USES, SOURCE CODE, MODIFICATIONS
12
+
13
+ We provide You with source code so that You can create Modifications of the original Software, where Modification means: a) any addition to or deletion from the contents of a file included in the original Software or previous Modifications created by You, or b) any new file that contains any part of the original Software or previous Modifications. While You retain all rights to any original work authored by You as part of the Modifications, We continue to own all copyright and other intellectual property rights in the Software.
14
+
15
+ 3. DISTRIBUTION
16
+
17
+ You may distribute the Software in any applications, frameworks, or elements (collectively referred to as an “Application” or “Applications”) that you develop using the Software in accordance with this License Agreement, provided that such distribution does not violate the restrictions set forth in section 4 of this License Agreement. You must not remove, obscure or interfere with any copyright, acknowledgment, attribution, trademark, warning or disclaimer statement affixed to, incorporated in or otherwise applied in connection with the Software.
18
+
19
+ You are required to ensure that the Software is not reused by or with any applications other than those with which You distribute it as permitted herein. For example, if You install the Software on a customer’s server, that customer is not permitted to use the Software independently of Your application, and must be informed as such.
20
+
21
+ You will not owe Us any royalties for Your distribution of the Software in accordance with this License Agreement.
22
+
23
+ 4. PROHIBITED USES
24
+
25
+ You may not, without Our prior written consent, redistribute the Software or Modifications other than by including the Software or a portion thereof within Your own product, which must have substantially different functionality than the Software or Modifications and must not allow any third party to use the Software or Modifications, or any portions thereof, for software development or application development purposes. You are explicitly not allowed to redistribute the Software or Modifications as part of any product that can be described as a development toolkit or library, an application builder, a website builder or any product that is intended for use by software, application, or website developers or designers. You are not allowed to redistribute any part of the Software documentation. You may not change or remove the copyright notice from any of the files included in the Software or Modifications.
26
+
27
+ UNDER NO CIRCUMSTANCES MAY YOU USE THE SOFTWARE FOR A PRODUCT THAT IS INTENDED FOR SOFTWARE OR APPLICATION DEVELOPMENT PURPOSES.
28
+
29
+ The Open Source version of the Software (“LGPL Version”) is licensed
30
+ under the terms of the GNU Lesser General Public License versions 3.0
31
+ (“LGPL”) and not under this License Agreement. If You, or another third
32
+ party, has, at any time, developed all (or any portions of) the
33
+ Application(s) using the LGPL Version, You may not combine such
34
+ development work with the Software and must license such Application(s)
35
+ (or any portions derived there from) under the terms of the GNU Lesser
36
+ General Public License version 3, a copy of which is located at
37
+ http://www.gnu.org/copyleft/lgpl.html.
38
+
39
+ 5. TERMINATION
40
+
41
+ This License Agreement and Your right to use the Software and Modifications will terminate immediately without notice if You fail to comply with the terms and conditions of this License Agreement. Upon termination, You agree to immediately cease using and destroy the Software or Modifications, including all accompanying documents. The provisions of sections 4, 5, 6, 7, 8, 9, 10 and 12 will survive any termination of this License Agreement.
42
+
43
+ 6. DISCLAIMER OF WARRANTIES
44
+
45
+ TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, WE AND OUR SUPPLIERS DISCLAIM ALL WARRANTIES AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE. WE DO NOT GUARANTEE THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, AND YOU ACKNOWLEDGE THAT IT IS NOT TECHNICALLY PRACTICABLE FOR US TO DO SO.
46
+
47
+ 7. LIMITATION OF LIABILITIES
48
+
49
+ TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL WE OR OUR SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION OR ANY OTHER PECUNIARY LAW) ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF WE HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY CASE, OUR ENTIRE LIABILITY UNDER ANY PROVISION OF THIS LICENSE AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR THE SOFTWARE.
50
+
51
+ 8. VERIFICATION
52
+
53
+ We or a certified auditor acting on Our behalf, may, upon its reasonable request and at its expense, audit You with respect to the use of the Software. Such audit may be conducted by mail, electronic means or through an in-person visit to Your place of business. Any such in-person audit shall be conducted during regular business hours at Your facilities and shall not unreasonably interfere with Your business activities. We shall not remove, copy, or redistribute any electronic material during the course of an audit. If an audit reveals that You are using the Software in a way that is in material violation of the terms of the License Agreement, then You shall pay Our reasonable costs of conducting the audit. In the case of a material violation, You agree to pay Us any amounts owing that are attributable to the unauthorized use. In the alternative, We reserve the right, at Our sole option, to terminate the licenses for the Software.
54
+
55
+ 9. THIRD PARTY SOFTWARE
56
+
57
+ Examples included in Software may provide links to third party libraries or code (collectively “Third Party Software”) to implement various functions. Third Party Software does not comprise part of the Software. In some cases, access to Third Party Software may be included along with the Software delivery as a convenience for demonstration purposes. Such source code and libraries may be included in the “…/examples” source tree delivered with the Software and do not comprise the Software. Licensee acknowledges (1) that some part of Third Party Software may require additional licensing of copyright and patents from the owners of such, and (2) that distribution of any of the Software referencing or including any portion of a Third Party Software may require appropriate licensing from such third parties.
58
+
59
+ 10. PAYMENT AND TAXES
60
+
61
+ If credit has been extended to You by Us, all payments under this License Agreement are due within thirty (30) days of the date We mail an invoice to You. If We have not extended credit to You, You shall be required to make payment concurrent with the delivery of the Software by Us. All amounts payable are gross amounts but exclusive of any value added tax, use tax, sales tax or similar tax. You shall be entitled to withhold from payments any applicable withholding taxes and comply with all applicable tax and employment legislation. Each party shall pay all taxes (including, but not limited to, taxes based upon its income) or levies imposed on it under applicable laws, regulations and tax treaties as a result of this Agreement and any payments made hereunder (including those required to be withheld or deducted from payments). Each party shall furnish evidence of such paid taxes as is sufficient to enable the other party to obtain any credits available to it, including original withholding tax certificates.
62
+
63
+ 11. MISCELLANEOUS
64
+
65
+ The license granted herein applies only to the version of the Software available when purchased in connection with the terms of this License Agreement. Any previous or subsequent license granted to You for use of the Software shall be governed by the terms and conditions of the agreement entered in connection with purchase of that version of the Software. You agree that you will comply with all applicable laws and regulations with respect to the Software, including without limitation all export and re-export control laws and regulations.
66
+
67
+ While redistributing the Software or Modifications thereof, You may choose to offer acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License Agreement. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on our behalf. You agree to indemnify, defend, and hold Us harmless from and against any liability incurred by, or claims asserted against, Us (i) by reason of Your accepting any such support, warranty, indemnity or additional liability; or (ii) arising out of the use, reproduction or distribution of Your Application, except to the extent such claim is solely based on the inclusion of the Software therein.
68
+
69
+ You agree to be identified as a customer of ours and You agree that We may refer to You by name, trade name and trademark, if applicable, and may briefly describe Your business in our marketing materials and web site.
70
+
71
+ You may not assign this License Agreement without Our prior written consent, which will not be unreasonably withheld. This License Agreement will inure to the benefit of Our successors and assigns.
72
+
73
+ You acknowledge that this License Agreement is complete and is the exclusive representation of our agreement. No oral or written information given by Us or on our behalf shall create a warranty or collateral contract, or in any way increase the scope of this License Agreement in any way, and You may not rely on any such oral or written information. No term or condition contained in any purchase order shall apply unless expressly accepted by Us in writing,
74
+
75
+ There are no implied licenses or other implied rights granted under this License Agreement, and all rights, save for those expressly granted hereunder, shall remain with Us and our licensors. In addition, no licenses or immunities are granted to the combination of the Software and/or Modifications, as applicable, with any other software or hardware not delivered by Us to You under this License Agreement.
76
+
77
+ If any provision in this License Agreement shall be determined to be invalid, such provision shall be deemed omitted; the remainder of this License Agreement shall continue in full force and effect. If any remedy provided is determined to have failed for its essential purpose, all limitations of liability and exclusions of damages set forth in this License Agreement shall remain in effect.
78
+
79
+ This License Agreement may be modified only by a written instrument signed by an authorized representative of each party.
80
+
81
+ This License Agreement is governed by the law of the State of Oregon, United States (notwithstanding conflicts of laws provisions), and all parties irrevocably submit to the jurisdiction of the courts of the State of Oregon and further agree to commence any litigation which may arise hereunder in the state or federal courts located in the judicial district of Multnomah County, Oregon, US.
82
+
83
+ If the Software or any related documentation is licensed to the U.S. government or any agency thereof, it will be deemed to be “commercial computer software” or “commercial computer software documentation,” pursuant to DFAR Section 227.7202 and FAR Section 12.212. Any use of the Software or related documentation by the U.S. government will be governed solely by the terms of this License Agreement.
data/Changes.md CHANGED
@@ -1,3 +1,18 @@
1
+ 2.4.0
2
+ -----------
3
+
4
+ - ActionMailer.delay.method now only tries to deliver if method returns a valid message.
5
+ - Logging now uses "MSG-#{Job ID}", not a random msg ID
6
+ - Allow generic Redis provider as environment variable. [#443]
7
+ - Add ability to customize sidekiq\_options with delay calls [#450]
8
+
9
+ ```ruby
10
+ Foo.delay(:retry => false).bar
11
+ Foo.delay(:retry => 10).bar
12
+ Foo.delay(:timeout => 10.seconds).bar
13
+ Foo.delay_for(5.minutes, :timeout => 10.seconds).bar
14
+ ```
15
+
1
16
  2.3.3
2
17
  -----------
3
18
 
data/LICENSE CHANGED
@@ -4,5 +4,6 @@ Sidekiq is an Open Source project licensed under the terms of
4
4
  the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
5
5
  for license text.
6
6
 
7
- A commercial license is available to those who buy Sidekiq Pro.
8
- Please see http://sidekiq.org/pro/ for more detail.
7
+ Sidekiq Pro has a commercial-friendly license allowing private forks
8
+ and modifications of Sidekiq. Please see http://sidekiq.org/pro/ for
9
+ more detail. You can find the commercial license terms in COMM-LICENSE.
data/README.md CHANGED
@@ -72,7 +72,6 @@ License
72
72
 
73
73
  Please see LICENSE for licensing details.
74
74
 
75
- <a href='http://www.pledgie.com/campaigns/16623'><img alt='Click here to lend your support to Open Source and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/16623.png?skin_name=chrome' border='0' /></a>
76
75
 
77
76
  Author
78
77
  -----------------
@@ -3,6 +3,8 @@
3
3
  # sidekiq -C config.yml
4
4
  ---
5
5
  :verbose: false
6
+ :pidfile: ./tmp/pids/sidekiq.pid
7
+ :namespace: sidekiq_namespace
6
8
  :concurrency: 25
7
9
  :queues:
8
10
  - [often, 7]
@@ -16,16 +16,19 @@ module Sidekiq
16
16
 
17
17
  def perform(yml)
18
18
  (target, method_name, args) = YAML.load(yml)
19
- target.send(method_name, *args).deliver
19
+ msg = target.send(method_name, *args)
20
+ # The email method can return nil, which causes ActionMailer to return
21
+ # an undeliverable empty message.
22
+ msg.deliver if msg && msg.to && msg.from
20
23
  end
21
24
  end
22
25
 
23
26
  module ActionMailer
24
- def delay
25
- Proxy.new(DelayedMailer, self)
27
+ def delay(options={})
28
+ Proxy.new(DelayedMailer, self, options)
26
29
  end
27
- def delay_for(interval)
28
- Proxy.new(DelayedMailer, self, Time.now.to_f + interval.to_f)
30
+ def delay_for(interval, options={})
31
+ Proxy.new(DelayedMailer, self, options.merge('at' => Time.now.to_f + interval.to_f))
29
32
  end
30
33
  end
31
34
 
@@ -21,11 +21,11 @@ module Sidekiq
21
21
  end
22
22
 
23
23
  module ActiveRecord
24
- def delay
25
- Proxy.new(DelayedModel, self)
24
+ def delay(options={})
25
+ Proxy.new(DelayedModel, self, options)
26
26
  end
27
- def delay_for(interval)
28
- Proxy.new(DelayedModel, self, Time.now.to_f + interval.to_f)
27
+ def delay_for(interval, options={})
28
+ Proxy.new(DelayedModel, self, options.merge('at' => Time.now.to_f + interval.to_f))
29
29
  end
30
30
  end
31
31
 
@@ -19,11 +19,11 @@ module Sidekiq
19
19
  end
20
20
 
21
21
  module Klass
22
- def delay
23
- Proxy.new(DelayedClass, self)
22
+ def delay(options={})
23
+ Proxy.new(DelayedClass, self, options)
24
24
  end
25
- def delay_for(interval)
26
- Proxy.new(DelayedClass, self, Time.now.to_f + interval.to_f)
25
+ def delay_for(interval, options={})
26
+ Proxy.new(DelayedClass, self, options.merge('at' => Time.now.to_f + interval.to_f))
27
27
  end
28
28
  end
29
29
 
@@ -1,10 +1,10 @@
1
1
  module Sidekiq
2
2
  module Extensions
3
3
  class Proxy < BasicObject
4
- def initialize(performable, target, at=nil)
4
+ def initialize(performable, target, options={})
5
5
  @performable = performable
6
6
  @target = target
7
- @at = at
7
+ @opts = options
8
8
  end
9
9
 
10
10
  def method_missing(name, *args)
@@ -14,11 +14,7 @@ module Sidekiq
14
14
  # to JSON and then deserialized on the other side back into a
15
15
  # Ruby object.
16
16
  obj = [@target, name, args]
17
- if @at
18
- @performable.perform_at(@at, ::YAML.dump(obj))
19
- else
20
- @performable.perform_async(::YAML.dump(obj))
21
- end
17
+ @performable.client_push({ 'class' => @performable, 'args' => [::YAML.dump(obj)] }.merge(@opts))
22
18
  end
23
19
  end
24
20
 
@@ -3,8 +3,8 @@ module Sidekiq
3
3
  module Server
4
4
  class Logging
5
5
 
6
- def call(*args)
7
- Sidekiq::Logging.with_context("#{args[0].class.to_s} MSG-#{args[0].object_id.to_s(36)}") do
6
+ def call(worker, item, queue)
7
+ Sidekiq::Logging.with_context("#{worker.class.to_s} MSG-#{item['jid']}") do
8
8
  begin
9
9
  start = Time.now
10
10
  logger.info { "start" }
@@ -20,6 +20,13 @@ module Sidekiq
20
20
  #
21
21
  # { 'class' => 'HardWorker', 'args' => [1, 2, 'foo'] }
22
22
  #
23
+ # The 'retry' option also accepts a number (in place of 'true'):
24
+ #
25
+ # { 'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => 5 }
26
+ #
27
+ # The job will be retried this number of times before giving up. (If simply
28
+ # 'true', Sidekiq retries 25 times)
29
+ #
23
30
  # We'll add a bit more data to the message to support retries:
24
31
  #
25
32
  # * 'queue' - the queue to use
@@ -35,13 +42,14 @@ module Sidekiq
35
42
  include Sidekiq::Util
36
43
 
37
44
  # delayed_job uses the same basic formula
38
- MAX_COUNT = 25
45
+ DEFAULT_MAX_RETRY_ATTEMPTS = 25
39
46
  DELAY = proc { |count| (count ** 4) + 15 }
40
47
 
41
48
  def call(worker, msg, queue)
42
49
  yield
43
50
  rescue Exception => e
44
51
  raise e unless msg['retry']
52
+ max_retry_attempts = retry_attempts_from(msg['retry'], DEFAULT_MAX_RETRY_ATTEMPTS)
45
53
 
46
54
  msg['queue'] = queue
47
55
  msg['error_message'] = e.message
@@ -60,7 +68,7 @@ module Sidekiq
60
68
  msg['error_backtrace'] = e.backtrace[0..msg['backtrace'].to_i]
61
69
  end
62
70
 
63
- if count <= MAX_COUNT
71
+ if count <= max_retry_attempts
64
72
  delay = DELAY.call(count)
65
73
  logger.debug { "Failure! Retry #{count} in #{delay} seconds" }
66
74
  retry_at = Time.now.to_f + delay
@@ -75,6 +83,14 @@ module Sidekiq
75
83
  raise e
76
84
  end
77
85
 
86
+ def retry_attempts_from(msg_retry, default)
87
+ if msg_retry.is_a?(Fixnum)
88
+ msg_retry
89
+ else
90
+ default
91
+ end
92
+ end
93
+
78
94
  end
79
95
  end
80
96
  end
@@ -95,7 +95,7 @@ module Sidekiq
95
95
  end
96
96
 
97
97
  # Singleton classes are not clonable.
98
- SINGLETON_CLASSES = [ NilClass, TrueClass, FalseClass, Symbol, Fixnum, Float ].freeze
98
+ SINGLETON_CLASSES = [ NilClass, TrueClass, FalseClass, Symbol, Fixnum, Float, Bignum ].freeze
99
99
 
100
100
  # Clone the arguments passed to the worker so that if
101
101
  # the message fails, what is pushed back onto Redis hasn't
@@ -5,7 +5,7 @@ require 'redis/namespace'
5
5
  module Sidekiq
6
6
  class RedisConnection
7
7
  def self.create(options={})
8
- url = options[:url] || ENV['REDISTOGO_URL'] || 'redis://localhost:6379/0'
8
+ url = options[:url] || determine_redis_provider || 'redis://localhost:6379/0'
9
9
  driver = options[:driver] || 'ruby'
10
10
  # need a connection for Fetcher and Retry
11
11
  size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 2) : 5)
@@ -24,5 +24,12 @@ module Sidekiq
24
24
  end
25
25
  end
26
26
  private_class_method :build_client
27
+
28
+ # Not public
29
+ def self.determine_redis_provider
30
+ return ENV['REDISTOGO_URL'] if ENV['REDISTOGO_URL']
31
+ provider = ENV['REDIS_PROVIDER'] || 'REDIS_URL'
32
+ ENV[provider]
33
+ end
27
34
  end
28
35
  end
@@ -1,6 +1,5 @@
1
1
  module Sidekiq
2
2
  module Worker
3
-
4
3
  ##
5
4
  # The Sidekiq testing infrastructure overrides perform_async
6
5
  # so that it does not actually touch the network. Instead it
@@ -20,25 +19,83 @@ module Sidekiq
20
19
  # assert_equal :something, HardWorker.jobs[0]['args'][0]
21
20
  #
22
21
  # assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
23
- # MyMailer.delayed.send_welcome_email('foo@example.com')
22
+ # MyMailer.delay.send_welcome_email('foo@example.com')
23
+ # assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
24
+ #
25
+ # You can also clear and drain all workers' jobs:
26
+ #
27
+ # assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
28
+ # assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
29
+ #
30
+ # MyMailer.delay.send_welcome_email('foo@example.com')
31
+ # MyModel.delay.do_something_hard
32
+ #
24
33
  # assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
34
+ # assert_equal 1, Sidekiq::Extensions::DelayedModel.jobs.size
35
+ #
36
+ # Sidekiq::Worker.clear_all # or .drain_all
37
+ #
38
+ # assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
39
+ # assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
40
+ #
41
+ # This can be useful to make sure jobs don't linger between tests:
42
+ #
43
+ # RSpec.configure do |config|
44
+ # config.before(:each) do
45
+ # Sidekiq::Worker.clear_all
46
+ # end
47
+ # end
48
+ #
49
+ # or for acceptance testing, i.e. with cucumber:
50
+ #
51
+ # AfterStep do
52
+ # Sidekiq::Worker.drain_all
53
+ # end
54
+ #
55
+ # When I sign up as "foo@example.com"
56
+ # Then I should receive a welcome email to "foo@example.com"
25
57
  #
26
58
  module ClassMethods
27
59
  alias_method :client_push_old, :client_push
60
+
28
61
  def client_push(opts)
29
62
  jobs << opts
30
63
  true
31
64
  end
32
65
 
66
+ # Jobs queued for this worker
33
67
  def jobs
34
- @pushed ||= []
68
+ Worker.jobs[self]
35
69
  end
36
70
 
71
+ # Clear all jobs for this worker
72
+ def clear
73
+ jobs.clear
74
+ end
75
+
76
+ # Drain and run all jobs for this worker
37
77
  def drain
38
78
  while job = jobs.shift do
39
79
  new.perform(*job['args'])
40
80
  end
41
81
  end
42
82
  end
83
+
84
+ class << self
85
+ def jobs # :nodoc:
86
+ @jobs ||= Hash.new { |hash, key| hash[key] = [] }
87
+ end
88
+
89
+ # Clear all queued jobs across all workers
90
+ def clear_all
91
+ jobs.clear
92
+ end
93
+
94
+ # Drain all queued jobs across all workers
95
+ def drain_all
96
+ jobs.keys.each(&:drain)
97
+ clear_all
98
+ end
99
+ end
43
100
  end
44
101
  end
@@ -1,3 +1,3 @@
1
1
  module Sidekiq
2
- VERSION = "2.3.3"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -68,8 +68,8 @@ module Sidekiq
68
68
  hash
69
69
  end
70
70
 
71
- def client_push(*args) # :nodoc:
72
- Sidekiq::Client.push(*args)
71
+ def client_push(item) # :nodoc:
72
+ Sidekiq::Client.push(stringify_keys(item))
73
73
  end
74
74
 
75
75
  end
@@ -29,6 +29,14 @@ class TestExtensions < MiniTest::Unit::TestCase
29
29
  assert_equal 1, Sidekiq.redis {|c| c.llen('queue:default') }
30
30
  end
31
31
 
32
+ it 'uses and stringifies specified options' do
33
+ assert_equal [], Sidekiq::Client.registered_queues
34
+ assert_equal 0, Sidekiq.redis {|c| c.llen('queue:notdefault') }
35
+ MyModel.delay(queue: :notdefault).long_class_method
36
+ assert_equal ['notdefault'], Sidekiq::Client.registered_queues
37
+ assert_equal 1, Sidekiq.redis {|c| c.llen('queue:notdefault') }
38
+ end
39
+
32
40
  it 'allows delayed scheduling of AR class methods' do
33
41
  assert_equal 0, Sidekiq.redis {|c| c.zcard('schedule') }
34
42
  MyModel.delay_for(5.days).long_class_method
@@ -0,0 +1,46 @@
1
+ require 'helper'
2
+ require 'sidekiq/redis_connection'
3
+
4
+ class TestRedisConnection < MiniTest::Unit::TestCase
5
+
6
+ describe ".create" do
7
+
8
+ def with_env_var(var, uri, skip_provider=false)
9
+ vars = ['REDISTOGO_URL', 'REDIS_PROVIDER', 'REDIS_URL'] - [var]
10
+ vars.each do |v|
11
+ next if skip_provider
12
+ ENV[v] = nil
13
+ end
14
+ ENV[var] = uri
15
+ assert_equal uri, Sidekiq::RedisConnection.determine_redis_provider
16
+ ENV[var] = nil
17
+ end
18
+
19
+ describe "with REDISTOGO_URL set" do
20
+ it "sets connection URI to RedisToGo" do
21
+ with_env_var 'REDISTOGO_URL', 'redis://redis-to-go:6379/0'
22
+ end
23
+ end
24
+
25
+ describe "with REDIS_PROVIDER set" do
26
+ it "sets connection URI to the provider" do
27
+ uri = 'redis://sidekiq-redis-provider:6379/0'
28
+ provider = 'SIDEKIQ_REDIS_PROVIDER'
29
+
30
+ ENV['REDIS_PROVIDER'] = provider
31
+ ENV[provider] = uri
32
+
33
+ with_env_var provider, uri, true
34
+
35
+ ENV[provider] = nil
36
+ end
37
+ end
38
+
39
+ describe "with REDIS_URL set" do
40
+ it "sets connection URI to custom uri" do
41
+ with_env_var 'REDIS_URL', 'redis://redis-uri:6379/0'
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -88,17 +88,51 @@ class TestRetry < MiniTest::Unit::TestCase
88
88
  @redis.verify
89
89
  end
90
90
 
91
- it 'throws away old messages after too many retries' do
91
+ it 'handles a recurring failed message before reaching user-specifed max' do
92
+ @redis.expect :zadd, 1, ['retry', String, String]
92
93
  now = Time.now.utc
93
- msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>25}
94
+ msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], 'retry' => 11, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>10}
94
95
  handler = Sidekiq::Middleware::Server::RetryJobs.new
95
96
  assert_raises RuntimeError do
96
97
  handler.call('', msg, 'default') do
97
98
  raise "kerblammo!"
98
99
  end
99
100
  end
101
+ assert_equal 'default', msg["queue"]
102
+ assert_equal 'kerblammo!', msg["error_message"]
103
+ assert_equal 'RuntimeError', msg["error_class"]
104
+ assert_equal 11, msg["retry_count"]
105
+ assert msg["failed_at"]
100
106
  @redis.verify
101
107
  end
108
+
109
+ it 'throws away old messages after too many retries (using the default)' do
110
+ now = Time.now.utc
111
+ msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry"=>true, "retry_count"=>25}
112
+ @redis.expect :zadd, 1, [ 'retry', String, String ]
113
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
114
+ assert_raises RuntimeError do
115
+ handler.call('', msg, 'default') do
116
+ raise "kerblammo!"
117
+ end
118
+ end
119
+ # MiniTest can't assert that a method call did NOT happen!?
120
+ assert_raises(MockExpectationError) { @redis.verify }
121
+ end
122
+
123
+ it 'throws away old messages after too many retries (using user-specified max)' do
124
+ now = Time.now.utc
125
+ msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry"=>3, "retry_count"=>3}
126
+ @redis.expect :zadd, 1, [ 'retry', String, String ]
127
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
128
+ assert_raises RuntimeError do
129
+ handler.call('', msg, 'default') do
130
+ raise "kerblammo!"
131
+ end
132
+ end
133
+ # MiniTest can't assert that a method call did NOT happen!?
134
+ assert_raises(MockExpectationError) { @redis.verify }
135
+ end
102
136
  end
103
137
 
104
138
  describe 'poller' do
@@ -110,5 +110,72 @@ class TestTesting < MiniTest::Unit::TestCase
110
110
  end
111
111
  assert_equal 0, StoredWorker.jobs.size
112
112
  end
113
+
114
+ class FirstWorker
115
+ include Sidekiq::Worker
116
+ class_attribute :count
117
+ self.count = 0
118
+ def perform
119
+ self.class.count += 1
120
+ end
121
+ end
122
+
123
+ class SecondWorker
124
+ include Sidekiq::Worker
125
+ class_attribute :count
126
+ self.count = 0
127
+ def perform
128
+ self.class.count += 1
129
+ end
130
+ end
131
+
132
+ it 'clears jobs across all workers' do
133
+ Sidekiq::Worker.jobs.clear
134
+ FirstWorker.count = 0
135
+ SecondWorker.count = 0
136
+
137
+ assert_equal 0, FirstWorker.jobs.size
138
+ assert_equal 0, SecondWorker.jobs.size
139
+
140
+ FirstWorker.perform_async
141
+ SecondWorker.perform_async
142
+
143
+ assert_equal 1, FirstWorker.jobs.size
144
+ assert_equal 1, SecondWorker.jobs.size
145
+
146
+ Sidekiq::Worker.clear_all
147
+
148
+ assert_equal 0, FirstWorker.jobs.size
149
+ assert_equal 0, SecondWorker.jobs.size
150
+
151
+ assert_equal 0, FirstWorker.count
152
+ assert_equal 0, SecondWorker.count
153
+ end
154
+
155
+ it 'drains jobs across all workers' do
156
+ Sidekiq::Worker.jobs.clear
157
+ FirstWorker.count = 0
158
+ SecondWorker.count = 0
159
+
160
+ assert_equal 0, FirstWorker.jobs.size
161
+ assert_equal 0, SecondWorker.jobs.size
162
+
163
+ assert_equal 0, FirstWorker.count
164
+ assert_equal 0, SecondWorker.count
165
+
166
+ FirstWorker.perform_async
167
+ SecondWorker.perform_async
168
+
169
+ assert_equal 1, FirstWorker.jobs.size
170
+ assert_equal 1, SecondWorker.jobs.size
171
+
172
+ Sidekiq::Worker.drain_all
173
+
174
+ assert_equal 0, FirstWorker.jobs.size
175
+ assert_equal 0, SecondWorker.jobs.size
176
+
177
+ assert_equal 1, FirstWorker.count
178
+ assert_equal 1, SecondWorker.count
179
+ end
113
180
  end
114
181
  end
@@ -4,7 +4,8 @@
4
4
  //= require_tree .
5
5
 
6
6
  $(function() {
7
- $.timeago.settings.allowFuture = true
7
+ $.timeago.settings.allowFuture = true;
8
+ $.timeago.settings.refreshMillis = 0;
8
9
  $("time").timeago();
9
10
  });
10
11
 
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.3.3
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70336704844540 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70336704844540
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: redis-namespace
27
- requirement: &70336704844000 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70336704844000
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: connection_pool
38
- requirement: &70336704843460 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 0.9.2
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70336704843460
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: celluloid
49
- requirement: &70336704842820 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 0.12.0
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70336704842820
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.12.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: multi_json
60
- requirement: &70336704842140 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '1'
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *70336704842140
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: minitest
71
- requirement: &70336704841420 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '3'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70336704841420
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '3'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: sinatra
82
- requirement: &70336704840840 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70336704840840
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: slim
93
- requirement: &70336704840180 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70336704840180
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: rake
104
- requirement: &70336704839540 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *70336704839540
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: actionmailer
115
- requirement: &70336704855400 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ~>
@@ -120,10 +165,15 @@ dependencies:
120
165
  version: '3'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *70336704855400
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '3'
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: activerecord
126
- requirement: &70336704854900 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ~>
@@ -131,10 +181,15 @@ dependencies:
131
181
  version: '3'
132
182
  type: :development
133
183
  prerelease: false
134
- version_requirements: *70336704854900
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: '3'
135
190
  - !ruby/object:Gem::Dependency
136
191
  name: pry
137
- requirement: &70336704854520 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
138
193
  none: false
139
194
  requirements:
140
195
  - - ! '>='
@@ -142,7 +197,12 @@ dependencies:
142
197
  version: '0'
143
198
  type: :development
144
199
  prerelease: false
145
- version_requirements: *70336704854520
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
146
206
  description: Simple, efficient message processing for Ruby
147
207
  email:
148
208
  - mperham@gmail.com
@@ -155,6 +215,7 @@ files:
155
215
  - .gitignore
156
216
  - .rvmrc
157
217
  - .travis.yml
218
+ - COMM-LICENSE
158
219
  - Changes.md
159
220
  - Gemfile
160
221
  - LICENSE
@@ -218,6 +279,7 @@ files:
218
279
  - test/test_fetch.rb
219
280
  - test/test_middleware.rb
220
281
  - test/test_processor.rb
282
+ - test/test_redis_connection.rb
221
283
  - test/test_retry.rb
222
284
  - test/test_scheduling.rb
223
285
  - test/test_stats.rb
@@ -266,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
328
  version: '0'
267
329
  requirements: []
268
330
  rubyforge_project:
269
- rubygems_version: 1.8.15
331
+ rubygems_version: 1.8.24
270
332
  signing_key:
271
333
  specification_version: 3
272
334
  summary: Simple, efficient message processing for Ruby
@@ -281,6 +343,7 @@ test_files:
281
343
  - test/test_fetch.rb
282
344
  - test/test_middleware.rb
283
345
  - test/test_processor.rb
346
+ - test/test_redis_connection.rb
284
347
  - test/test_retry.rb
285
348
  - test/test_scheduling.rb
286
349
  - test/test_stats.rb