resque-restriction 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +2 -0
- data/README.md +21 -13
- data/lib/resque/plugins/restriction.rb +1 -1
- data/lib/resque/restriction/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a9aca569bec8f4f56affc4d804245a9fe335e7
|
4
|
+
data.tar.gz: '019f6b3d2bb70ea8fea85fbbcc194a00288382c2'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2f1e27d8a499374a074b525c8ea64d57503ddd2a3d9a4f018ecc54639af1bb468d31f84c16c246fb00b8ee3718e2418cfc497b119f753513906ad2778569e6a
|
7
|
+
data.tar.gz: 11dda9dc7c6629f268d55c1b7a7856d86db329e2e58c5db380cc84d9bd8a05d3c02cc19cbbcafd7b54b5d9d5776a7463286082698f61b988d66a31d14c10e1a0
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,6 +9,10 @@ Resque Restriction is a plugin for the [Resque](https://github.com/resque/resque
|
|
9
9
|
|
10
10
|
Resque Restriction requires Resque 1.7.0.
|
11
11
|
|
12
|
+
*Please make sure your workers are checking restriction_xxx queue.*.
|
13
|
+
e.g., if you add restriction plugin to high_priority queue, you need to
|
14
|
+
check restriction_high_priority queue.
|
15
|
+
|
12
16
|
Attention
|
13
17
|
---------
|
14
18
|
|
@@ -36,13 +40,15 @@ To use
|
|
36
40
|
|
37
41
|
It is especially useful when a system has an email invitation resque job, because sending emails too frequentyly will be treated as a spam. What you should do for the InvitationJob is to inherit it from Resque::Plugins::RestrictionJob class and add restrict definition. Example:
|
38
42
|
|
39
|
-
|
40
|
-
|
43
|
+
```ruby
|
44
|
+
class InvitationJob
|
45
|
+
extend Resque::Plugins::Restriction
|
41
46
|
|
42
|
-
|
47
|
+
restrict :per_day => 1000, :per_hour => 100, :per_300 => 30
|
43
48
|
|
44
|
-
|
45
|
-
|
49
|
+
# rest of your class here
|
50
|
+
end
|
51
|
+
```
|
46
52
|
|
47
53
|
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.
|
48
54
|
|
@@ -53,18 +59,20 @@ Advance
|
|
53
59
|
|
54
60
|
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:
|
55
61
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
restrict :per_day => 40
|
62
|
+
```ruby
|
63
|
+
class GenerateFacebookShares
|
64
|
+
extend Resque::Plugins::Restriction
|
60
65
|
|
61
|
-
|
62
|
-
[self.to_s, options["user_id"]].join(":")
|
63
|
-
end
|
66
|
+
restrict :per_day => 40
|
64
67
|
|
65
|
-
|
68
|
+
def self.restriction_identifier(options)
|
69
|
+
[self.to_s, options["user_id"]].join(":")
|
66
70
|
end
|
67
71
|
|
72
|
+
# rest of your class here
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
68
76
|
options["user_id"] returns the user's facebook uid, the key point is that the different restriction_identifiers can restrict different job execution numbers.
|
69
77
|
|
70
78
|
|
@@ -70,7 +70,7 @@ module Resque
|
|
70
70
|
when :per_month then Date.today.strftime("%Y-%m")
|
71
71
|
when :per_year then Date.today.year.to_s
|
72
72
|
else period.to_s =~ /^per_(\d+)$/ and (Time.now.to_i / $1.to_i).to_s end
|
73
|
-
[self.restriction_identifier(*args), period_str].compact.join(":")
|
73
|
+
[RESTRICTION_QUEUE_PREFIX, self.restriction_identifier(*args), period_str].compact.join(":")
|
74
74
|
end
|
75
75
|
|
76
76
|
def restriction_identifier(*args)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-restriction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,7 +78,6 @@ files:
|
|
78
78
|
- ".gitignore"
|
79
79
|
- CHANGELOG.md
|
80
80
|
- Gemfile
|
81
|
-
- Gemfile.lock
|
82
81
|
- LICENSE
|
83
82
|
- README.md
|
84
83
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
resque-restriction (0.5.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.3)
|
10
|
-
mono_logger (1.1.0)
|
11
|
-
multi_json (1.11.2)
|
12
|
-
rack (1.6.4)
|
13
|
-
rack-protection (1.5.3)
|
14
|
-
rack
|
15
|
-
rake (10.5.0)
|
16
|
-
redis (3.2.1)
|
17
|
-
redis-namespace (1.5.1)
|
18
|
-
redis (~> 3.0, >= 3.0.4)
|
19
|
-
resque (1.25.2)
|
20
|
-
mono_logger (~> 1.0)
|
21
|
-
multi_json (~> 1.0)
|
22
|
-
redis-namespace (~> 1.3)
|
23
|
-
sinatra (>= 0.9.2)
|
24
|
-
vegas (~> 0.1.2)
|
25
|
-
rspec (3.7.0)
|
26
|
-
rspec-core (~> 3.7.0)
|
27
|
-
rspec-expectations (~> 3.7.0)
|
28
|
-
rspec-mocks (~> 3.7.0)
|
29
|
-
rspec-core (3.7.1)
|
30
|
-
rspec-support (~> 3.7.0)
|
31
|
-
rspec-expectations (3.7.0)
|
32
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.7.0)
|
34
|
-
rspec-mocks (3.7.0)
|
35
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.7.0)
|
37
|
-
rspec-support (3.7.1)
|
38
|
-
sinatra (1.4.5)
|
39
|
-
rack (~> 1.4)
|
40
|
-
rack-protection (~> 1.4)
|
41
|
-
tilt (~> 1.3, >= 1.3.4)
|
42
|
-
tilt (1.4.1)
|
43
|
-
vegas (0.1.11)
|
44
|
-
rack (>= 1.0.0)
|
45
|
-
|
46
|
-
PLATFORMS
|
47
|
-
ruby
|
48
|
-
|
49
|
-
DEPENDENCIES
|
50
|
-
bundler (~> 1.16)
|
51
|
-
rake (~> 10.0)
|
52
|
-
resque (>= 1.7.0)
|
53
|
-
resque-restriction!
|
54
|
-
rspec (~> 3.0)
|
55
|
-
|
56
|
-
BUNDLED WITH
|
57
|
-
1.16.0
|