activejob-traffic_control 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2906ae48cd5953f18837860c3685e3ebf8a2dd84
4
- data.tar.gz: 5bb69b07b5439da6c1f56d5674fbfec37bd111d8
3
+ metadata.gz: 511ad5f30c21f83e11d8f6918f145c4fb0d73d9e
4
+ data.tar.gz: c39128c8888ce24cc9d0b0341763a259ae40d54c
5
5
  SHA512:
6
- metadata.gz: 5887b615c100a481113967f5541c4e4d86621a4ce9a4ae604dcac4c524c53d0a097ec30ce9a5d88d6bd30d18fdcce4646d8731d660a190532fc496a31b19a39a
7
- data.tar.gz: d5ccb7e7fa1c4782bcc1650a62d6f1ca17117aace77a130e2c6561714d97619faec95f86b5526516772f3ca429361ce4701e727c212585d8f896528b0de2170c
6
+ metadata.gz: 6db8cce696dfeb0b984b7bc8abf9dd1f591c9d8fa3f1ce83536c5d05a91517b03fb35ae32f8e64a8f5427bd47b1f4689c182775d6cc54ea765c9305f278667ba
7
+ data.tar.gz: 55b4efb468ba9771612992816b615a5bc93f70b9adf2233c1fe12d6875548917f1300cbad99a9cbeff0fda40c30b731e36ef0ce1b0d77a5004f1ef7014b51fbd
@@ -0,0 +1,11 @@
1
+ ## 0.1.2
2
+
3
+ - Use #class_attribute instead of #attr_accessor for various configuration (thanks avokhmin!)
4
+
5
+ ## 0.1.1
6
+
7
+ - Improve documentation and comments.
8
+
9
+ ## 0.1.0
10
+
11
+ - First release.
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 (you can set `drop: false` to have the re-enqueued instead)
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
- @job_concurrency = {
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
- @job_throttling = {
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 = {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveJob
4
4
  module TrafficControl
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
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.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-07-01 00:00:00.000000000 Z
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: