dynamodb-mutex 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Clearhaus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.rst CHANGED
@@ -1,6 +1,22 @@
1
1
  DynamoDB Mutex
2
2
  ==============
3
3
 
4
+ .. image:: https://travis-ci.org/clearhaus/dynamodb-mutex.svg?branch=master
5
+ :alt: Build Status
6
+ :target: https://travis-ci.org/clearhaus/dynamodb-mutex
7
+
8
+ .. image:: https://codeclimate.com/github/clearhaus/dynamodb-mutex/badges/gpa.svg
9
+ :alt: Code Climate
10
+ :target: https://codeclimate.com/github/clearhaus/dynamodb-mutex
11
+
12
+ .. image:: https://gemnasium.com/clearhaus/dynamodb-mutex.svg
13
+ :alt: Dependency Status
14
+ :target: https://gemnasium.com/clearhaus/dynamodb-mutex
15
+
16
+ .. image:: http://img.shields.io/license/MIT.png?color=green
17
+ :alt: MIT License
18
+ :target: http://opensource.org/licenses/MIT
19
+
4
20
  Using DynamoDB, it implements a simple semaphore that can be used to coordinate
5
21
  access to shared data from multiple concurrent hosts or processes.
6
22
 
@@ -1,4 +1,4 @@
1
- require 'aws-sdk'
1
+ require 'aws-sdk-v1'
2
2
  require_relative 'logging'
3
3
 
4
4
  module DynamoDBMutex
@@ -11,6 +11,9 @@ module DynamoDBMutex
11
11
 
12
12
  TABLE_NAME = 'dynamodb-mutex'
13
13
 
14
+ # May raise
15
+ # DynamoDBMutex::LockError
16
+ # Timeout::Error
14
17
  def with_lock name = 'default.lock', opts = {}
15
18
  opts[:stale_after] ||= 10 # seconds
16
19
  opts[:wait_for_other] ||= 1 # seconds
@@ -31,7 +34,12 @@ module DynamoDBMutex
31
34
  acquire_timeout = Time.now.to_i + opts[:wait_for_other]
32
35
 
33
36
  while Time.now.to_i < acquire_timeout
34
- delete(name) if stale?(name, opts[:stale_after])
37
+ logger.info "#{pid} checking if #{name} is stale"
38
+ if stale?(name, opts[:stale_after])
39
+ logger.info "#{pid} deleting #{name} because it is stale"
40
+ delete(name)
41
+ end
42
+
35
43
  begin
36
44
  table.items.put({:id => name, :created => Time.now.to_i},
37
45
  :unless_exists => :id)
@@ -55,7 +63,7 @@ module DynamoDBMutex
55
63
  def pid
56
64
  @hostname ||= Socket.gethostname
57
65
 
58
- "#{@hostname}-#{Process.pid}"
66
+ "#{@hostname}-#{Process.pid}-#{Thread.current.object_id}"
59
67
  end
60
68
 
61
69
  def stale?(name, ttl)
@@ -90,5 +98,5 @@ module DynamoDBMutex
90
98
 
91
99
  @table
92
100
  end
93
- end
101
+ end
94
102
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module DynamoDBMutex
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'ostruct'
3
2
 
4
3
  describe DynamoDBMutex::Lock do
5
4
 
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'rspec'
4
4
  require 'fake_dynamo'
5
- require 'aws-sdk'
5
+ require 'aws-sdk-v1'
6
6
 
7
7
  AWS.config(:use_ssl => false,
8
8
  :dynamo_db_endpoint => 'localhost',
@@ -14,7 +14,9 @@ AWS.config(:use_ssl => false,
14
14
  require 'dynamodb-mutex'
15
15
 
16
16
  RSpec.configure do |config|
17
- DynamoDBMutex::Lock.logger = Logger.new(StringIO.new, 1024*1024, 10)
17
+ log_stream = ENV['DEBUG'] =~ (/^(true|t|yes|y|1)$/i) ? STDERR : StringIO.new
18
+
19
+ DynamoDBMutex::Lock.logger = Logger.new(log_stream)
18
20
 
19
21
  dynamo_thread = nil
20
22
 
@@ -23,7 +25,7 @@ RSpec.configure do |config|
23
25
  FakeDynamo::Storage.instance.load_aof
24
26
 
25
27
  dynamo_thread = Thread.new do
26
- $stdout = StringIO.new
28
+ $stdout = log_stream # Throw FakeDynamo's stdout logging somewhere else.
27
29
  FakeDynamo::Server.run!(port: 4567, bind: 'localhost') do |server|
28
30
  if server.respond_to?('config') && server.config.respond_to?('[]=')
29
31
  server.config[:AccessLog] = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb-mutex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-10 00:00:00.000000000 Z
12
+ date: 2015-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: aws-sdk
15
+ name: aws-sdk-v1
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -91,22 +91,23 @@ dependencies:
91
91
  - - '='
92
92
  - !ruby/object:Gem::Version
93
93
  version: 0.1.3
94
- description: dynamodb-mutex implements a simple mutex that can be used to coordinateaccess
95
- to shared data from multiple concurrent hosts
94
+ description: dynamodb-mutex implements a simple mutex that can be used to coordinate
95
+ access to shared data from multiple concurrent hosts
96
96
  email: dy@clearhaus.com
97
97
  executables: []
98
98
  extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
101
  - Rakefile
102
- - lib/dynamodb_mutex/logging.rb
102
+ - lib/dynamodb-mutex.rb
103
103
  - lib/dynamodb_mutex/lock.rb
104
+ - lib/dynamodb_mutex/logging.rb
104
105
  - lib/dynamodb_mutex/version.rb
105
- - lib/dynamodb-mutex.rb
106
106
  - lib/dynamodb_mutex.rb
107
- - spec/spec_helper.rb
108
107
  - spec/dynamodb_mutex_spec.rb
108
+ - spec/spec_helper.rb
109
109
  - README.rst
110
+ - LICENSE
110
111
  homepage: http://github.com/clearhaus/dynamodb-mutex
111
112
  licenses:
112
113
  - MIT
@@ -120,12 +121,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
121
  - - ! '>='
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
124
+ segments:
125
+ - 0
126
+ hash: 409537590926897434
123
127
  required_rubygems_version: !ruby/object:Gem::Requirement
124
128
  none: false
125
129
  requirements:
126
130
  - - ! '>='
127
131
  - !ruby/object:Gem::Version
128
132
  version: '0'
133
+ segments:
134
+ - 0
135
+ hash: 409537590926897434
129
136
  requirements: []
130
137
  rubyforge_project:
131
138
  rubygems_version: 1.8.23.2