resque-restriction 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,9 +25,26 @@ It is especially useful when a system has an email invitation resque job, becaus
25
25
  #rest of your class here
26
26
  end
27
27
 
28
- That means the InvitationJob can not be executed more than 1000 times per day, 100 times per hour and 30 times per 300 seconds.
28
+ That means the InvitationJob can not be executed more than 1000 times per day, 100 times per hour and 30 times per 300 seconds. All restrictions have to be met for the job to execute.
29
29
 
30
- The argument of restrict method is a hash, the key of the hash is a period time, including :per_minute, :per_hour, :per_day, :per_week, :per_month, :per_year, and you can also define any period like :per_300 means per 300 seconds. the value of the hash is the job execution limit number in a period.
30
+ The argument of restrict method is a hash, the key of the hash is a period time, including :concurrent, :per_minute, :per_hour, :per_day, :per_week, :per_month, :per_year, and you can also define any period like :per_300 means per 300 seconds. The value of the hash is the job execution limit number in a period. The :concurrent option restricts the number of jobs that run simultaneously.
31
+
32
+ Advance
33
+ -------
34
+
35
+ You can also add customized restriction as you like. For example, we have a job to restrict the facebook post numbers 40 times per user per day, we can define as:
36
+
37
+ class GenerateFacebookShares < Resque::Plugins::RestrictionJob
38
+ restrict :per_day => 40
39
+
40
+ def self.identifier(options)
41
+ [self.to_s, options["user_id"]].join(":")
42
+ end
43
+
44
+ #rest of your class here
45
+ end
46
+
47
+ options["user_id"] returns the user's facebook uid, the key point is that the different identifiers can restrict different job execution numbers.
31
48
 
32
49
  Contributing
33
50
  ------------
@@ -44,6 +61,10 @@ Author
44
61
  ------
45
62
  Richard Huang :: flyerhzm@gmail.com :: @flyerhzm
46
63
 
64
+ Contributors
65
+ ------------
66
+ Matt Conway :: matt@conwaysplace.com :: @mattconway
67
+
47
68
  Copyright
48
69
  ---------
49
70
  Copyright (c) 2010 Richard Huang. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -54,6 +54,10 @@ module Resque
54
54
  end
55
55
  end
56
56
 
57
+ def on_failure_restriction(ex, *args)
58
+ after_perform_restriction(*args)
59
+ end
60
+
57
61
  def redis_key(period, *args)
58
62
  period_str = case period
59
63
  when :concurrent then "*"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{resque-restriction}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Huang"]
12
- s.date = %q{2010-06-29}
12
+ s.date = %q{2010-07-10}
13
13
  s.description = %q{resque-restriction is an extension to resque queue system that restricts the execution number of certain jobs in a period time, the exceeded jobs will be executed at the next period.}
14
14
  s.email = %q{flyerhzm@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -71,6 +71,12 @@ describe Resque::Plugins::RestrictionJob do
71
71
  Resque.redis.get(ConcurrentRestrictionJob.redis_key(:concurrent)).should == "1"
72
72
  end
73
73
 
74
+ it "should increment execution number when concurrent job fails" do
75
+ ConcurrentRestrictionJob.should_receive(:perform).and_raise("bad")
76
+ perform_job(ConcurrentRestrictionJob, "any args") rescue nil
77
+ Resque.redis.get(ConcurrentRestrictionJob.redis_key(:concurrent)).should == "1"
78
+ end
79
+
74
80
  it "should put the job into restriction queue when execution count < 0" do
75
81
  Resque.redis.set(OneHourRestrictionJob.redis_key(:per_hour), 0)
76
82
  result = perform_job(OneHourRestrictionJob, "any args")
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Richard Huang
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-29 00:00:00 +08:00
17
+ date: 2010-07-10 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency