lockistics 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Lockistics is basically a distributed mutex on Redis with statistics collecting
4
4
 
5
5
  The likely use case for locking would be something like a Raketask that you don't want running multiple instances at once.
6
6
 
7
- The likely use case for the statistics part would be that you want to how often something is being called or if a certain Raketask has been run today or not. You can also use it to find memory leaks or slow methods, kind of private NewRelic with zero features.
7
+ The likely use case for the statistics part would be that you want to know how often something is being called or if a certain Raketask has been run today or not. You can also use it to find memory leaks or slow methods, kind of private NewRelic with zero features.
8
8
 
9
9
  ## Installation
10
10
 
@@ -51,10 +51,11 @@ These are the default settings :
51
51
  Lockistics.configure do |config|
52
52
  config.redis = Redis.new
53
53
  config.namespace = "lockistics"
54
- config.expire = 300 # seconds
55
- config.sleep = 0.5 # seconds to sleep between retries
56
- config.retries = 10 # retry times
57
- config.raise = true # raise Lockistics::TimeoutException when lock fails
54
+ config.expire = 300 # seconds
55
+ config.sleep = 0.5 # seconds to sleep between retries
56
+ config.retries = 10 # retry times
57
+ config.raise = true # raise Lockistics::TimeoutException when lock fails
58
+ config.pass_through = false # don't do anything, let everything pass through
58
59
  end
59
60
  ```
60
61
 
@@ -161,6 +162,16 @@ You can query statistics for locking/metering keys.
161
162
  :last_run:time => #<Time..>}
162
163
  ```
163
164
 
165
+ ## Storage
166
+
167
+ - All keys are prefixed with the `configuration.namespace`
168
+ - namespace.KEY_NAME.lock for lock
169
+ - namespace.KEY_NAME.dailies is a sorted set with timestamps
170
+ - namespace.KEY_NAME.daily.TIMESTAMP is a hash with keys like "invocations", "max.time"
171
+ - same goes for hourlies (but with hourly + hourlies in the key)
172
+ - namespace.KEY_NAME.total has all time stats for the key
173
+ - namespace.known_keys is a sorted set of known keys
174
+
164
175
  ## Contributing
165
176
 
166
177
  1. Fork it
@@ -10,13 +10,15 @@ module Lockistics
10
10
  attr_accessor :sleep
11
11
  attr_accessor :retries
12
12
  attr_accessor :raise
13
+ attr_accessor :pass_through
13
14
 
14
15
  def initialize
15
- @redis = Redis.new
16
- @namespace = 'lockistics'
17
- @expire = 10
18
- @sleep = 0.5
19
- @retries = 10
16
+ @redis = Redis.new
17
+ @namespace = 'lockistics'
18
+ @expire = 10
19
+ @sleep = 0.5
20
+ @retries = 10
21
+ @pass_through = false
20
22
  end
21
23
 
22
24
  def lock_defaults
@@ -17,6 +17,7 @@ module Lockistics
17
17
  end
18
18
 
19
19
  def acquire_lock
20
+ return true if options[:pass_through]
20
21
  Lockistics.known_keys(key)
21
22
  if got_lock?
22
23
  true
@@ -46,6 +47,7 @@ module Lockistics
46
47
  end
47
48
 
48
49
  def release_lock
50
+ return true if options[:pass_through]
49
51
  @exceeded_before_release = redis.del(namespaced_key) == 0
50
52
  end
51
53
 
@@ -1,6 +1,12 @@
1
1
  require 'os'
2
2
 
3
3
  module Lockistics
4
+ class DummyMeter
5
+ def method_missing(*args, &block)
6
+ # do nothing
7
+ end
8
+ end
9
+
4
10
  class Meter
5
11
 
6
12
  attr_accessor :key, :options
@@ -27,7 +33,7 @@ module Lockistics
27
33
 
28
34
  def initialize(key, options={})
29
35
  @key = key
30
- @options = options
36
+ @options = {:pass_through => Lockistics.configuration.pass_through}.merge(options)
31
37
  @lock_timeouts = 0
32
38
  end
33
39
 
@@ -42,13 +48,17 @@ module Lockistics
42
48
 
43
49
  def perform(&block)
44
50
  raise ArgumentError, "perform called without block" unless block_given?
45
- before_perform
46
- lock.nil? ? yield(self) : with_lock(&block)
51
+ if options[:pass_through]
52
+ yield DummyMeter.new
53
+ else
54
+ before_perform
55
+ lock.nil? ? yield(self) : with_lock(&block)
56
+ end
47
57
  rescue Lockistics::LockTimeout
48
58
  @lock_timeouts = 1
49
59
  raise
50
60
  ensure
51
- after_perform
61
+ after_perform unless options[:pass_through]
52
62
  end
53
63
 
54
64
  # You can add custom metrics during runtime
@@ -1,3 +1,3 @@
1
1
  module Lockistics
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/lockistics.rb CHANGED
@@ -27,10 +27,11 @@ module Lockistics
27
27
  # Lockistics.configure do |config|
28
28
  # config.redis = Redis.new
29
29
  # config.namespace = "production.locks"
30
- # config.expire = 300 # seconds
31
- # config.sleep = 0.5 # seconds to sleep between retries
32
- # config.retries = 10 # retry times
33
- # config.raise = true # raise Lockistics::TimeoutException when lock fails
30
+ # config.expire = 300 # seconds
31
+ # config.sleep = 0.5 # seconds to sleep between retries
32
+ # config.retries = 10 # retry times
33
+ # config.raise = true # raise Lockistics::TimeoutException when lock fails
34
+ # config.pass_through = false # don't do anything, just pass everything through
34
35
  # end
35
36
  def self.configure(&block)
36
37
  yield configuration
data/lockistics.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Lockistics::VERSION
9
9
  spec.authors = ["Kimmo Lehto"]
10
10
  spec.email = ["kimmo.lehto@gmail.com"]
11
- spec.description = %q{Statsistics collecting locking}
11
+ spec.description = %q{Statsistics collecting shared mutex on Redis}
12
12
  spec.summary = %q{With lockistics you can use Redis to create distributed locks and collect statistics how often and how long your locks are held}
13
13
  spec.homepage = "https://github.com/kke/lockistics"
14
14
  spec.license = "MIT"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockistics
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kimmo Lehto
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-05-19 00:00:00 Z
18
+ date: 2014-05-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -102,7 +102,7 @@ dependencies:
102
102
  prerelease: false
103
103
  type: :development
104
104
  requirement: *id006
105
- description: Statsistics collecting locking
105
+ description: Statsistics collecting shared mutex on Redis
106
106
  email:
107
107
  - kimmo.lehto@gmail.com
108
108
  executables: []