activejob-traffic_control 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +17 -1
- data/lib/active_job/traffic_control/concurrency.rb +3 -3
- data/lib/active_job/traffic_control/throttle.rb +3 -3
- data/lib/active_job/traffic_control/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 511ad5f30c21f83e11d8f6918f145c4fb0d73d9e
|
4
|
+
data.tar.gz: c39128c8888ce24cc9d0b0341763a259ae40d54c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6db8cce696dfeb0b984b7bc8abf9dd1f591c9d8fa3f1ce83536c5d05a91517b03fb35ae32f8e64a8f5427bd47b1f4689c182775d6cc54ea765c9305f278667ba
|
7
|
+
data.tar.gz: 55b4efb468ba9771612992816b615a5bc93f70b9adf2233c1fe12d6875548917f1300cbad99a9cbeff0fda40c30b731e36ef0ce1b0d77a5004f1ef7014b51fbd
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -35,11 +35,27 @@ ActiveJob::TrafficControl.client = ConnectionPool.new(size: 5, timeout: 5) { Red
|
|
35
35
|
class CanThrottleJob < ActiveJob::Base
|
36
36
|
include ActiveJob::TrafficControl::Throttle
|
37
37
|
|
38
|
+
throttle threshold: 2, period: 1.second
|
39
|
+
|
40
|
+
def perform
|
41
|
+
# no more than two of `CanThrottleJob` will run every second
|
42
|
+
# if more than that attempt to run, they will be re-enqueued to run in a random time
|
43
|
+
# ranging from 1 - 5x the period (so, 1-5 seconds in this case)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
If you do not care about the job being re-enqueued (if it's scheduled to run otherwise, or dropping will have no ill effect), you can specify `drop: true` instead. The `drop: true` flag also applies to `Concurrency`, below.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
class CanThrottleAndDropJob < ActiveJob::Base
|
52
|
+
include ActiveJob::TrafficControl::Throttle
|
53
|
+
|
38
54
|
throttle threshold: 2, period: 1.second, drop: true
|
39
55
|
|
40
56
|
def perform
|
41
57
|
# no more than two of `CanThrottleJob` will run every second
|
42
|
-
# if more than that attempt to run, they will be dropped
|
58
|
+
# if more than that attempt to run, they will be dropped
|
43
59
|
end
|
44
60
|
end
|
45
61
|
```
|
@@ -8,12 +8,10 @@ module ActiveJob
|
|
8
8
|
CONCURRENCY_REENQUEUE_DELAY = ENV["RACK_ENV"] == "test" ? 1...5 : 30...(60 * 5)
|
9
9
|
|
10
10
|
class_methods do
|
11
|
-
attr_accessor :job_concurrency
|
12
|
-
|
13
11
|
def concurrency(threshold, drop: true, key: nil, wait_timeout: 0.1, stale_timeout: 60 * 10)
|
14
12
|
raise ArgumentError, "Concurrent jobs needs to be an integer > 0" if threshold.to_i < 1
|
15
13
|
|
16
|
-
|
14
|
+
self.job_concurrency = {
|
17
15
|
threshold: threshold.to_i,
|
18
16
|
drop: drop,
|
19
17
|
wait_timeout: wait_timeout.to_f,
|
@@ -30,6 +28,8 @@ module ActiveJob
|
|
30
28
|
included do
|
31
29
|
include ActiveJob::TrafficControl::Base
|
32
30
|
|
31
|
+
class_attribute :job_concurrency, instance_accessor: false
|
32
|
+
|
33
33
|
around_perform do |job, block|
|
34
34
|
if self.class.job_concurrency.present?
|
35
35
|
lock_options = {
|
@@ -6,12 +6,10 @@ module ActiveJob
|
|
6
6
|
extend ::ActiveSupport::Concern
|
7
7
|
|
8
8
|
class_methods do
|
9
|
-
attr_accessor :job_throttling
|
10
|
-
|
11
9
|
def throttle(threshold:, period:, drop: false, key: nil)
|
12
10
|
raise ArgumentError, "Threshold needs to be an integer > 0" if threshold.to_i < 1
|
13
11
|
|
14
|
-
|
12
|
+
self.job_throttling = {
|
15
13
|
threshold: threshold,
|
16
14
|
period: period,
|
17
15
|
drop: drop,
|
@@ -27,6 +25,8 @@ module ActiveJob
|
|
27
25
|
included do
|
28
26
|
include ActiveJob::TrafficControl::Base
|
29
27
|
|
28
|
+
class_attribute :job_throttling, instance_accessor: false
|
29
|
+
|
30
30
|
around_perform do |job, block|
|
31
31
|
if self.class.job_throttling.present?
|
32
32
|
lock_options = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activejob-traffic_control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Elser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- ".gitignore"
|
134
134
|
- ".rubocop.yml"
|
135
135
|
- ".travis.yml"
|
136
|
+
- CHANGELOG.md
|
136
137
|
- Gemfile
|
137
138
|
- README.md
|
138
139
|
- Rakefile
|
@@ -169,4 +170,3 @@ signing_key:
|
|
169
170
|
specification_version: 4
|
170
171
|
summary: Traffic control for ActiveJob
|
171
172
|
test_files: []
|
172
|
-
has_rdoc:
|