throttler 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,26 +1,25 @@
1
1
  Throttler
2
2
  =========
3
3
 
4
- Throttler is a tired, cranky module that throttles parallel-running Ruby scripts on a single machine.
4
+ Throttler is a tired, cranky module that helps you throttle stuff in parallel-running Ruby scripts on a single machine.
5
5
 
6
6
  ![Mapplethorpe](https://github.com/papercavalier/throttler/raw/master/mapplethorpe_chains.jpg)
7
7
 
8
8
  Example
9
9
  -------
10
10
 
11
- Our very own peculiar use case: We have multiple Resque workers hitting the Amazon IP on multiple addresses and want to make sure they don't fire more than once per locale per IP.
11
+ Our very own use case: We have multiple Resque workers hitting the Amazon IP on multiple addresses and want to make sure they don't fire more than once per locale per IP.
12
+
13
+ Here's some pseudo code:
12
14
 
13
15
  class Worker
14
16
  include Throttler
15
17
 
16
- attr_accessor :locale,
17
- :interface
18
-
19
- def perform
18
+ def perform(*args)
20
19
  scope = "#{locale}-#{interface}"
21
20
  freq = 1.0
22
21
 
23
- throttle(scope, interval) do
22
+ throttle(scope, freq) do
24
23
  # perform a request
25
24
  end
26
25
  end
@@ -1,4 +1,4 @@
1
1
  module Throttler #:nodoc:
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
4
4
 
data/lib/throttler.rb CHANGED
@@ -2,16 +2,13 @@ require "throttler/timer"
2
2
 
3
3
  # = Throttler
4
4
  #
5
- # An old, rusty throttler that gets the job done
5
+ # A tired, cranky module that helps you throttle stuff in parallel-running Ruby
6
+ # scripts on a single machine. It gets the job done.
6
7
  module Throttler
7
-
8
- # Throttles the frequency in which a block is run
9
- #
10
- # Optionally pass a scope and interval.
11
- def throttle(scope="throttler", interval=1.0)
8
+ def throttle(scope="throttler",freq=1.0)
12
9
  timer = Timer.new(scope)
13
10
  timer.lock
14
- sleep [timer.timestamp + interval - Time.now.to_f, 0.0].max
11
+ sleep [timer.timestamp + freq - Time.now.to_f, 0.0].max
15
12
  timer.timestamp = Time.now.to_f
16
13
  timer.unlock
17
14
  yield if block_given?
@@ -27,7 +27,7 @@ describe Throttler do
27
27
  end
28
28
 
29
29
  context "by default" do
30
- it "namespaces as `throttler`" do
30
+ it "names scope as `throttler`" do
31
31
  foo.throttle
32
32
  FileTest.exists?("/tmp/.throttler").should be_true
33
33
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Hakan Ensari
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 2.1.0
34
34
  type: :development
35
35
  version_requirements: *id001
36
- description: A tired, cranky module that throttles parallel-running Ruby scripts on a single machine.
36
+ description: A tired, cranky module that helps you throttle stuff in parallel-running Ruby scripts on a single machine. A tired, cranky module that throttles parallel-running Ruby scripts on a single machine.
37
37
  email:
38
38
  - code@papercavalier.com
39
39
  executables: []