pid_lock 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/pid_lock.rb +21 -14
- data/lib/pid_lock/version.rb +1 -1
- data/pid_lock.gemspec +2 -2
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4bdb79fac62a06bf4139aaddacee881160ad977e69e361ea7c8486769bf3a1ee
|
4
|
+
data.tar.gz: e7a8b13bef7732a94ef6816f77efe3f25483001780e476807c34565897e5acbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f3592e81e367de369cb4cbb74a8abc0329eae88b2df32d36f3f5ab54316d5b1dadc8507ac7cf723621414d5dab1cdc7dcb6e380bccb4b20076016671ea00a8f
|
7
|
+
data.tar.gz: 2521c04322aa72042a351fd822ddfc86809713deec2c1c5581ee254337b655cb17831acc0ed89f1b2342d16bb353a420d89ebd2c57216fd45b35bad4fffa5938
|
data/lib/pid_lock.rb
CHANGED
@@ -3,37 +3,44 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
module PidLock
|
5
5
|
class << self
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@@pid_path = path
|
6
|
+
attr_writer :pid_path
|
7
|
+
def pid_path
|
8
|
+
@pid_path || "tmp/pid_locks"
|
10
9
|
end
|
11
10
|
|
12
|
-
def
|
13
|
-
|
11
|
+
def ensure_single_running(pid_name)
|
12
|
+
return if locked?(pid_name)
|
13
|
+
PidLock.lock(pid_name)
|
14
|
+
begin
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
PidLock.unlock(pid_name)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
def lock(pid_name)
|
17
|
-
Dir.
|
18
|
-
File.write(File.join(pid_path, "#{pid_name}.pid"),
|
22
|
+
Dir.exist?(pid_path) || FileUtils.mkdir_p(pid_path)
|
23
|
+
File.write(File.join(pid_path, "#{pid_name}.pid"), $PID)
|
19
24
|
end
|
20
25
|
|
21
26
|
def locked?(pid_name)
|
22
|
-
return false unless File.
|
27
|
+
return false unless File.exist?(File.join(pid_path, "#{pid_name}.pid"))
|
23
28
|
begin
|
24
29
|
Process.kill(0, pid(pid_name))
|
25
30
|
return true
|
26
|
-
rescue
|
31
|
+
rescue StandardError
|
27
32
|
self.unlock(pid_name)
|
28
33
|
return false
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
37
|
def stop(pid_name)
|
33
|
-
return unless File.
|
38
|
+
return unless File.exist?(File.join(pid_path, "#{pid_name}.pid"))
|
34
39
|
pid = File.read(File.join(pid_path, "#{pid_name}.pid"))
|
35
|
-
|
36
|
-
|
40
|
+
return if pid.to_s.empty?
|
41
|
+
begin
|
42
|
+
Process.kill("TERM", pid.to_i)
|
43
|
+
rescue StandardError
|
37
44
|
end
|
38
45
|
unlock(pid_name)
|
39
46
|
end
|
@@ -43,7 +50,7 @@ module PidLock
|
|
43
50
|
end
|
44
51
|
|
45
52
|
def unlock(pid_name)
|
46
|
-
if File.
|
53
|
+
if File.exist?(File.join(pid_path, "#{pid_name}.pid"))
|
47
54
|
File.delete(File.join(pid_path, "#{pid_name}.pid"))
|
48
55
|
end
|
49
56
|
end
|
data/lib/pid_lock/version.rb
CHANGED
data/pid_lock.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1
|
22
|
-
spec.add_development_dependency "rake", "
|
21
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
22
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
23
23
|
spec.add_development_dependency "test-unit", "~> 2.5"
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pid_lock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xuxiangyang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
|
-
|
91
|
-
rubygems_version: 2.4.8
|
90
|
+
rubygems_version: 3.0.8
|
92
91
|
signing_key:
|
93
92
|
specification_version: 4
|
94
93
|
summary: ruby pid lock file
|