dynalock 0.2.0 → 0.2.1
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 +5 -5
- data/.circleci/config.yml +23 -0
- data/README.md +15 -21
- data/dynalock.gemspec +2 -4
- data/lib/dynalock/lock.rb +4 -4
- data/lib/dynalock/version.rb +1 -1
- metadata +5 -6
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f4a5e0eb8835887a34d6a5ea224408acd7422f25c24d3948b84e564ab9195d5
|
4
|
+
data.tar.gz: a2ee95736f0530e3ed8370d6f599c044f9be877cebfbbd13c0326cef051e17b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ddd7cccd14cf904a8ab1f5f3b1327c3fdbea9d6d7da15d87cb14504d387da2b151a284466e93c20da385b1febff9939ce4082c107bcd61e1fc47b3b6be3405d
|
7
|
+
data.tar.gz: 04bfe9235c7380e388cf0304fa3f4ceb15691585a03f9a0cc16b0497ae519b1f0435948cf7f60101b120416c73765153e9371111c714ddb1629ede1f0db015aa
|
@@ -0,0 +1,23 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
working_directory: ~/dynalock
|
6
|
+
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.4
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- checkout
|
12
|
+
|
13
|
+
# Dependencies
|
14
|
+
- restore_cache:
|
15
|
+
key: gem-cache-{{ checksum "Gemfile.lock" }}
|
16
|
+
- run: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
17
|
+
- save_cache:
|
18
|
+
key: gem-cache-{{ checksum "Gemfile.lock" }}
|
19
|
+
paths:
|
20
|
+
- vendor/bundle
|
21
|
+
|
22
|
+
# Test
|
23
|
+
- run: bundle exec rake test
|
data/README.md
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# Dynalock
|
2
2
|
|
3
|
-
Dynalock is a distributed lock that uses
|
4
|
-
|
3
|
+
*Dynalock* is a distributed lock that uses *DynamoDB*.
|
5
4
|
|
6
5
|
## Background
|
7
6
|
|
8
|
-
At
|
9
|
-
too big,
|
10
|
-
present. Dynalock solves this issue, ensuring that any new task
|
7
|
+
At *Tourlane* we were running cronjobs through *Amazon ECS*. Once the cluster became
|
8
|
+
too big, *CloudWatch* was scheduling tasks, even if the same task was already
|
9
|
+
present. *Dynalock* solves this issue, ensuring that any new task exits and fails
|
11
10
|
before starting the real work.
|
12
11
|
|
13
|
-
The first assumption is that something like this should
|
12
|
+
The first assumption is that something like this should exist, but normally
|
14
13
|
not as a command line program (if you found any, please let us know). So we
|
15
14
|
created our own.
|
16
15
|
|
@@ -30,21 +29,17 @@ Or install it yourself as:
|
|
30
29
|
|
31
30
|
$ gem install dynalock
|
32
31
|
|
33
|
-
You need to create a table in
|
34
|
-
The default table name is "locks"
|
35
|
-
|
32
|
+
You need to create a table in *DynamoDB* with "id" as a primary key, and "expires" as expires.
|
33
|
+
The default table name is "locks".
|
36
34
|
|
37
35
|
## Usage
|
38
36
|
|
39
|
-
|
40
|
-
Set the environment variables to its proper values.
|
41
|
-
|
37
|
+
Set the following environment variables to their proper values:
|
42
38
|
|
43
39
|
AWS_ACCESS_KEY_ID
|
44
40
|
AWS_REGION
|
45
41
|
AWS_SECRET_ACCESS_KEY
|
46
42
|
|
47
|
-
|
48
43
|
### Usage inside ruby
|
49
44
|
|
50
45
|
```ruby
|
@@ -52,7 +47,7 @@ require 'dynalock'
|
|
52
47
|
|
53
48
|
include Dynalock::Lock
|
54
49
|
|
55
|
-
|
50
|
+
acquire_lock(context: "my_lock", table: TABLE, owner: @owner, expire_time: 10)
|
56
51
|
refresh_lock(context: "my_lock", table: TABLE, owner: @owner, expire_time: 10)
|
57
52
|
with_lock(context: "my_lock", table: TABLE, owner: @owner) { "Only run this" }
|
58
53
|
```
|
@@ -60,19 +55,18 @@ with_lock(context: "my_lock", table: TABLE, owner: @owner) { "Only run this" }
|
|
60
55
|
Most of the paramenters are optional
|
61
56
|
|
62
57
|
```ruby
|
63
|
-
|
58
|
+
acquire_lock(context: "my_lock")
|
64
59
|
refresh_lock(context: "my_lock")
|
65
60
|
with_lock(context: "my_lock") { "Only run this" }
|
66
61
|
```
|
67
62
|
|
68
|
-
|
69
63
|
### Usage through the command line
|
70
64
|
|
71
65
|
```sh
|
72
66
|
$ dynalock my_program
|
73
67
|
```
|
74
68
|
|
75
|
-
This will try to
|
69
|
+
This will try to acquire a lock in *DynamoDB* for 10 seconds, and refresh it every 5 seconds and run your program. The command will be context.
|
76
70
|
|
77
71
|
## Development
|
78
72
|
|
@@ -88,8 +82,8 @@ git commits and tags, and push the `.gem` file to
|
|
88
82
|
|
89
83
|
## Contributing
|
90
84
|
|
91
|
-
Bug reports and pull requests are welcome on GitHub at
|
92
|
-
https://github.com/
|
85
|
+
Bug reports and pull requests are welcome on *GitHub* at
|
86
|
+
https://github.com/tourlane/dynalock. This project is intended to be a safe,
|
93
87
|
welcoming space for collaboration, and contributors are expected to adhere to
|
94
88
|
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
95
89
|
|
@@ -100,7 +94,7 @@ License](https://opensource.org/licenses/MIT).
|
|
100
94
|
|
101
95
|
## Code of Conduct
|
102
96
|
|
103
|
-
Everyone interacting in the Dynalock project’s codebases, issue trackers, chat
|
97
|
+
Everyone interacting in the *Dynalock* project’s codebases, issue trackers, chat
|
104
98
|
rooms and mailing lists is expected to follow the [code of
|
105
|
-
conduct](https://github.com/
|
99
|
+
conduct](https://github.com/tourlane/dynalock/blob/master/CODE_OF_CONDUCT.md).
|
106
100
|
|
data/dynalock.gemspec
CHANGED
@@ -6,16 +6,14 @@ require "dynalock/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "dynalock"
|
8
8
|
spec.version = Dynalock::VERSION
|
9
|
-
spec.authors = ["Guillermo
|
9
|
+
spec.authors = ["Guillermo Ávarez"]
|
10
10
|
spec.email = ["guillermo@cientifico.net"]
|
11
11
|
|
12
12
|
spec.summary = %q{Distributed lock using dynamodb}
|
13
|
-
spec.description = %q{dynalock is a distributed lock that uses Amazon Web Service Dynamod DB
|
13
|
+
spec.description = %q{dynalock is a distributed lock that uses Amazon Web Service Dynamod DB}
|
14
14
|
spec.homepage = "https://github.com/tourlane/dynalock"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
18
|
f.match(%r{^(test|spec|features)/})
|
21
19
|
end
|
data/lib/dynalock/lock.rb
CHANGED
@@ -3,12 +3,12 @@ require 'aws-sdk-dynamodb'
|
|
3
3
|
module Dynalock
|
4
4
|
module Lock
|
5
5
|
class Locked < Exception ; end
|
6
|
-
def
|
6
|
+
def acquire_lock(context:, owner: lock_default_owner, table: "locks", expire_time: 10)
|
7
7
|
dynamodb_client.put_item(
|
8
8
|
table_name: table,
|
9
9
|
item: {
|
10
10
|
id: context,
|
11
|
-
lock_owner: owner,
|
11
|
+
lock_owner: owner,
|
12
12
|
expires: Time.now.utc.to_i + expire_time
|
13
13
|
},
|
14
14
|
condition_expression: "attribute_not_exists(expires) OR expires < :expires",
|
@@ -27,7 +27,7 @@ module Dynalock
|
|
27
27
|
key: { id: context },
|
28
28
|
update_expression: "SET expires = :expires",
|
29
29
|
condition_expression: "attribute_exists(expires) AND expires > :now AND lock_owner = :owner",
|
30
|
-
expression_attribute_values: {
|
30
|
+
expression_attribute_values: {
|
31
31
|
":expires": Time.now.utc.to_i + expire_time,
|
32
32
|
":owner": owner,
|
33
33
|
":now": Time.now.utc.to_i
|
@@ -41,7 +41,7 @@ module Dynalock
|
|
41
41
|
def with_lock(context:, owner: lock_default_owner, table: "locks")
|
42
42
|
expire_time = 5
|
43
43
|
|
44
|
-
result =
|
44
|
+
result = acquire_lock(context: context, owner: owner, table: table, expire_time: expire_time)
|
45
45
|
raise Locked.new if result == false
|
46
46
|
|
47
47
|
thread = Thread.new {
|
data/lib/dynalock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynalock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Guillermo
|
7
|
+
- Guillermo Ávarez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-dynamodb
|
@@ -67,7 +67,6 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.0'
|
69
69
|
description: dynalock is a distributed lock that uses Amazon Web Service Dynamod DB
|
70
|
-
(Ruby api and command line... command)
|
71
70
|
email:
|
72
71
|
- guillermo@cientifico.net
|
73
72
|
executables:
|
@@ -75,8 +74,8 @@ executables:
|
|
75
74
|
extensions: []
|
76
75
|
extra_rdoc_files: []
|
77
76
|
files:
|
77
|
+
- ".circleci/config.yml"
|
78
78
|
- ".gitignore"
|
79
|
-
- ".travis.yml"
|
80
79
|
- CODE_OF_CONDUCT.md
|
81
80
|
- Gemfile
|
82
81
|
- Gemfile.lock
|
@@ -111,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
110
|
version: '0'
|
112
111
|
requirements: []
|
113
112
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.7.8
|
115
114
|
signing_key:
|
116
115
|
specification_version: 4
|
117
116
|
summary: Distributed lock using dynamodb
|