Skip to content

Commit

Permalink
Improve documentation, and bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelser committed Jul 14, 2016
1 parent 1fcc834 commit ab911fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,27 @@ ActiveJob::TrafficControl.client = ConnectionPool.new(size: 5, timeout: 5) { Red
class CanThrottleJob < ActiveJob::Base
include ActiveJob::TrafficControl::Throttle

throttle threshold: 2, period: 1.second

def perform
# no more than two of `CanThrottleJob` will run every second
# if more than that attempt to run, they will be re-enqueued to run in a random time
# ranging from 1 - 5x the period (so, 1-5 seconds in this case)
end
end
```

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.

```ruby
class CanThrottleAndDropJob < ActiveJob::Base
include ActiveJob::TrafficControl::Throttle

throttle threshold: 2, period: 1.second, drop: true

def perform
# no more than two of `CanThrottleJob` will run every second
# if more than that attempt to run, they will be dropped (you can set `drop: false` to have the re-enqueued instead)
# if more than that attempt to run, they will be dropped
end
end
```
Expand Down
2 changes: 1 addition & 1 deletion lib/active_job/traffic_control/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module ActiveJob
module TrafficControl
VERSION = "0.1.0"
VERSION = "0.1.1"
end
end

0 comments on commit ab911fe

Please sign in to comment.