singleton_process 0.0.2 → 0.0.3
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.
- data/README.md +6 -0
- data/lib/singleton_process.rb +7 -1
- data/spec/singleton_process_spec.rb +18 -0
- metadata +28 -28
data/README.md
CHANGED
@@ -28,6 +28,12 @@ The basic usage is quite simple: just supply a process name (will show up in `ps
|
|
28
28
|
SingletonProcess.new('long_running_process').lock
|
29
29
|
```
|
30
30
|
|
31
|
+
If you just want to exit if you can't lock call `#lock_or_exit`
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
SingletonProcess.new('long_running_process').lock_or_exit # will call Kernel.exit if it is already running.
|
35
|
+
```
|
36
|
+
|
31
37
|
By default the lock file will be removed when the process exits, but if you need to clear the lock earlier you can call #unlock.
|
32
38
|
|
33
39
|
```ruby
|
data/lib/singleton_process.rb
CHANGED
@@ -3,7 +3,7 @@ require 'pathname'
|
|
3
3
|
class SingletonProcess
|
4
4
|
class AlreadyRunningError < RuntimeError; end
|
5
5
|
|
6
|
-
VERSION = '0.0.
|
6
|
+
VERSION = '0.0.3'
|
7
7
|
|
8
8
|
attr_accessor :name, :root_path, :app_name
|
9
9
|
private :name=
|
@@ -33,6 +33,12 @@ class SingletonProcess
|
|
33
33
|
$0 = "#{app_name} | #{name} | started #{Time.now}"
|
34
34
|
end
|
35
35
|
|
36
|
+
def lock_or_exit
|
37
|
+
lock
|
38
|
+
rescue AlreadyRunningError
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
36
42
|
def run!
|
37
43
|
lock
|
38
44
|
yield if block_given?
|
@@ -171,6 +171,24 @@ describe SingletonProcess do
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
+
describe "#lock_or_exit" do
|
175
|
+
context "when it is not already running" do
|
176
|
+
it "should be running." do
|
177
|
+
singleton.lock
|
178
|
+
singleton.pid.should eql(Process.pid)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when it is already running" do
|
183
|
+
it "should call exit." do
|
184
|
+
instance1 = described_class.new(process_name)
|
185
|
+
instance1.lock
|
186
|
+
|
187
|
+
expect{singleton.lock_or_exit}.to raise_error(SystemExit)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
174
192
|
describe "run!" do
|
175
193
|
it "should yield." do
|
176
194
|
ran = false
|
metadata
CHANGED
@@ -1,58 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton_process
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Robert Jackson
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
|
16
|
+
prerelease: false
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
17
18
|
requirements:
|
18
|
-
- -
|
19
|
+
- - ~>
|
19
20
|
- !ruby/object:Gem::Version
|
20
21
|
version: 2.12.0
|
21
22
|
none: false
|
22
|
-
|
23
|
+
type: :development
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- -
|
26
|
+
- - ~>
|
25
27
|
- !ruby/object:Gem::Version
|
26
28
|
version: 2.12.0
|
27
29
|
none: false
|
28
|
-
prerelease: false
|
29
|
-
type: :development
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: childprocess
|
32
|
-
|
32
|
+
prerelease: false
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
33
34
|
requirements:
|
34
|
-
- -
|
35
|
+
- - ~>
|
35
36
|
- !ruby/object:Gem::Version
|
36
37
|
version: 0.3.8
|
37
38
|
none: false
|
38
|
-
|
39
|
+
type: :development
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
41
|
requirements:
|
40
|
-
- -
|
42
|
+
- - ~>
|
41
43
|
- !ruby/object:Gem::Version
|
42
44
|
version: 0.3.8
|
43
45
|
none: false
|
44
|
-
|
45
|
-
|
46
|
-
description: Ensure that a given process is only running once. Helpful for ensure that scheduled tasks do not overlap if they run longer than the scheduled interval.
|
46
|
+
description: Ensure that a given process is only running once. Helpful for ensure
|
47
|
+
that scheduled tasks do not overlap if they run longer than the scheduled interval.
|
47
48
|
email:
|
48
49
|
- robert.w.jackson@me.com
|
49
50
|
executables: []
|
50
51
|
extensions: []
|
51
52
|
extra_rdoc_files: []
|
52
53
|
files:
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- .travis.yml
|
56
57
|
- Gemfile
|
57
58
|
- LICENSE.txt
|
58
59
|
- README.md
|
@@ -63,30 +64,29 @@ files:
|
|
63
64
|
- spec/spec_helper.rb
|
64
65
|
homepage: https://github.com/rjackson/singleton_process
|
65
66
|
licenses: []
|
66
|
-
post_install_message:
|
67
|
+
post_install_message:
|
67
68
|
rdoc_options: []
|
68
69
|
require_paths:
|
69
70
|
- lib
|
70
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
72
|
requirements:
|
72
|
-
- -
|
73
|
+
- - ! '>='
|
73
74
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
75
|
-
MA==
|
75
|
+
version: '0'
|
76
76
|
none: false
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- -
|
79
|
+
- - ! '>='
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
82
|
-
MA==
|
81
|
+
version: '0'
|
83
82
|
none: false
|
84
83
|
requirements: []
|
85
|
-
rubyforge_project:
|
84
|
+
rubyforge_project:
|
86
85
|
rubygems_version: 1.8.24
|
87
|
-
signing_key:
|
86
|
+
signing_key:
|
88
87
|
specification_version: 3
|
89
88
|
summary: Ensure that a given process is only running once.
|
90
89
|
test_files:
|
91
90
|
- spec/singleton_process_spec.rb
|
92
91
|
- spec/spec_helper.rb
|
92
|
+
has_rdoc:
|