resque-throttle 0.2.9 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.2.10
data/lib/resque/resque.rb CHANGED
@@ -7,7 +7,7 @@ module Resque
7
7
  class ThrottledError < RuntimeError; end
8
8
 
9
9
  def enqueue_with_throttle(klass, *args)
10
- if should_throttle?(klass)
10
+ if should_throttle?(klass, args)
11
11
  raise ThrottledError.new("#{klass} with key #{klass.key} has exceeded it's throttle limit")
12
12
  end
13
13
  enqueue_without_throttle(klass, *args)
@@ -17,15 +17,15 @@ module Resque
17
17
 
18
18
  private
19
19
 
20
- def should_throttle?(klass)
20
+ def should_throttle?(klass, *args)
21
21
  return false if !throttle_job?(klass) || klass.disabled
22
- return true if key_found?(klass)
23
- redis.set(klass.key, true, klass.can_run_every)
22
+ return true if key_found?(klass, args)
23
+ redis.set(klass.key(args), true, klass.can_run_every)
24
24
  return false
25
25
  end
26
26
 
27
- def key_found?(klass)
28
- redis.get(klass.key)
27
+ def key_found?(klass, *args)
28
+ redis.get(klass.key(args))
29
29
  end
30
30
 
31
31
  def throttle_job?(klass)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{resque-throttle}
8
- s.version = "0.2.9"
8
+ s.version = "0.2.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Scott J. Tamosunas"]
12
- s.date = %q{2010-02-22}
12
+ s.date = %q{2010-02-26}
13
13
  s.description = %q{resque-throttle is an extension to the resque queue system that restricts the frequency in which certain jobs are run. Add more description here.}
14
14
  s.email = %q{tamosunas@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -6,15 +6,15 @@ class ResqueTest < Test::Unit::TestCase
6
6
  setup do
7
7
  Resque.redis.flush_all
8
8
  assert_nil Resque.redis.get(OneHourThrottledJob.key)
9
- @bogus_args = [1, 2]
9
+ @bogus_args = "bogus_arg"
10
10
  end
11
11
 
12
12
  context "#enqueue" do
13
13
  should "add a throttled job key to the set with the proper TTL (Expire)" do
14
14
  Resque.expects(:enqueue_without_throttle).returns(true)
15
- assert Resque.enqueue(OneHourThrottledJob, @bogus_args)
16
- assert Resque.redis.get(OneHourThrottledJob.key)
17
- assert_equal 3600, Resque.redis.ttl(OneHourThrottledJob.key)
15
+ assert Resque.enqueue(IdentifierThrottledJob, @bogus_args)
16
+ assert Resque.redis.keys('*').include?("resque:IdentifierThrottledJob:my_bogus_arg")
17
+ assert_equal 3600, Resque.redis.ttl(IdentifierThrottledJob.key(@bogus_args))
18
18
  end
19
19
 
20
20
  context "job has not reached throttle limit" do
@@ -20,7 +20,7 @@ class ThrottledJobTest < Test::Unit::TestCase
20
20
 
21
21
  context "#identifier" do
22
22
  should "return an additional key identifier used in storing the key in the redis SET" do
23
- assert_equal "my_identifier", IdetifierThrottledJob.identifier
23
+ assert_equal "my_identifier", IdentifierThrottledJob.identifier("identifier")
24
24
  end
25
25
 
26
26
  should "return nil if not defined" do
@@ -41,7 +41,7 @@ class ThrottledJobTest < Test::Unit::TestCase
41
41
 
42
42
  context "#key" do
43
43
  should "consist of the class name and the identifier" do
44
- assert_equal "IdetifierThrottledJob:my_identifier", IdetifierThrottledJob.key
44
+ assert_equal "IdentifierThrottledJob:my_identifier", IdentifierThrottledJob.key("identifier")
45
45
  end
46
46
 
47
47
  should "consist of just the class name if the identifier is not provided" do
data/test/test_helper.rb CHANGED
@@ -28,7 +28,7 @@ class OneHourThrottledJob < Resque::ThrottledJob
28
28
  end
29
29
  end
30
30
 
31
- class IdetifierThrottledJob < Resque::ThrottledJob
31
+ class IdentifierThrottledJob < Resque::ThrottledJob
32
32
  @queue = :some_queue
33
33
 
34
34
  throttle :can_run_every => 3600
@@ -37,7 +37,8 @@ class IdetifierThrottledJob < Resque::ThrottledJob
37
37
  end
38
38
 
39
39
  def self.identifier(*args)
40
- "my_identifier"
40
+ first, second = *args
41
+ "my_#{first}"
41
42
  end
42
43
  end
43
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-throttle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott J. Tamosunas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-22 00:00:00 -08:00
12
+ date: 2010-02-26 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency