with_process_lock 0.1.0
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 +7 -0
- data/.codeclimate.yml +23 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/process_lock/version.rb +3 -0
- data/lib/process_lock/with_process_lock.rb +23 -0
- data/lib/process_lock.rb +6 -0
- data/process_lock.gemspec +31 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 83bf12114657b9d0326361df84cc0e452fea6f16
|
4
|
+
data.tar.gz: 71489d9b4a41f8d451662c879b85fe17703d4081
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8db55fc3de054a7a81348bc705b6b89dcd256dafd6a6e37d3ebcfb83b616f8bbcf4761320291b2a701adbedfd10e424e7453f7a8b7864bfcdb75d9a9f48afe50
|
7
|
+
data.tar.gz: a40bc3380ad50a2bd7bef7dfbe84257a358dffb7fc7f24df6627d83c63dd44d7c0f1c7a1a5a86ce020db61bb8c374c495338a089137bcd06adf98185ad77a60b
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
prepare:
|
2
|
+
fetch:
|
3
|
+
- url: "https://raw.githubusercontent.com/ForwardFinancing/code_styles/master/rubocop.yml"
|
4
|
+
path: ".rubocop.yml"
|
5
|
+
engines:
|
6
|
+
fixme:
|
7
|
+
enabled: true
|
8
|
+
rubocop:
|
9
|
+
enabled: true
|
10
|
+
file: ".rubocop.yml"
|
11
|
+
duplication:
|
12
|
+
enabled: true
|
13
|
+
config:
|
14
|
+
languages:
|
15
|
+
ruby:
|
16
|
+
mass_threshold: 20
|
17
|
+
ratings:
|
18
|
+
paths:
|
19
|
+
- Gemfile.lock
|
20
|
+
- "**.rb"
|
21
|
+
exclude_paths:
|
22
|
+
- test/
|
23
|
+
- bin/
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# ProcessLock
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/ForwardFinancing/process_lock)
|
4
|
+
|
5
|
+
[](https://codeclimate.com/github/ForwardFinancing/process_lock/coverage)
|
6
|
+
|
7
|
+
[](https://codeclimate.com/github/ForwardFinancing/process_lock)
|
8
|
+
|
9
|
+
|
10
|
+
[](https://travis-ci.org/ForwardFinancing/process_lock)
|
11
|
+
|
12
|
+
Ensures that multiple processes cannot be run concurrently, using redis.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'with_process_lock'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install process_lock
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
```
|
33
|
+
ProcessLock::WithProcessLock.execute('unique_key_for_your_process') do
|
34
|
+
# The code to run in the process
|
35
|
+
do_stuff
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/process_lock.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "process_lock"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module ProcessLock
|
2
|
+
class WithProcessLock
|
3
|
+
def self.execute(key, &blk)
|
4
|
+
if can_execute?(key)
|
5
|
+
redis.set(key, true)
|
6
|
+
yield blk
|
7
|
+
redis.del(key)
|
8
|
+
redis.quit
|
9
|
+
else
|
10
|
+
redis.quit
|
11
|
+
raise StandardError, "Can not run process because #{key} taken."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.can_execute?(key)
|
16
|
+
!redis.exists(key)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.redis
|
20
|
+
@_redis ||= Redis.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/process_lock.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'process_lock/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "with_process_lock"
|
8
|
+
spec.version = ProcessLock::VERSION
|
9
|
+
spec.authors = ["James Friedman", "Patrick Hereford", "Zach Cotter"]
|
10
|
+
spec.email = ["tech-management@forwardfinancing.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ensure that a ruby process cannot be run concurrently"
|
13
|
+
spec.description = "Ensures that a ruby process can't be run concurrently"
|
14
|
+
spec.homepage = "https://github.com/ForwardFinancing/process_lock"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency 'redis', '~> 3'
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
28
|
+
spec.add_development_dependency 'minitest-reporters'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_development_dependency 'simplecov'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: with_process_lock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Friedman
|
8
|
+
- Patrick Hereford
|
9
|
+
- Zach Cotter
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redis
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '3'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: bundler
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.14'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.14'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '10.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '10.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: minitest
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '5.0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '5.0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: codeclimate-test-reporter
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: minitest-reporters
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: pry
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: simplecov
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
description: Ensures that a ruby process can't be run concurrently
|
128
|
+
email:
|
129
|
+
- tech-management@forwardfinancing.com
|
130
|
+
executables: []
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".codeclimate.yml"
|
135
|
+
- ".gitignore"
|
136
|
+
- ".ruby-version"
|
137
|
+
- ".travis.yml"
|
138
|
+
- Gemfile
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- lib/process_lock.rb
|
144
|
+
- lib/process_lock/version.rb
|
145
|
+
- lib/process_lock/with_process_lock.rb
|
146
|
+
- process_lock.gemspec
|
147
|
+
homepage: https://github.com/ForwardFinancing/process_lock
|
148
|
+
licenses: []
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.6.11
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: Ensure that a ruby process cannot be run concurrently
|
170
|
+
test_files: []
|