single_instance 0.1.0 → 0.2.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.
- data/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/README.rdoc +10 -1
- data/Rakefile +4 -20
- data/lib/single_instance/version.rb +3 -0
- data/lib/single_instance.rb +19 -13
- data/single_instance.gemspec +23 -0
- data/test/test_single_instance.rb +7 -0
- metadata +55 -23
- data/VERSION +0 -1
data/.gitignore
CHANGED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2-p0@single_instance --create
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.rdoc
CHANGED
@@ -22,6 +22,15 @@ is running:
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
Run without a block, it creates a lock that lasts as long as the process is running:
|
26
|
+
|
27
|
+
# in Rakefile
|
28
|
+
task :all => [:exclusive, :this, :that, :whatever]
|
29
|
+
task :exclusive do
|
30
|
+
SingleInstance.exclusive_non_blocking(:build_models) || exit
|
31
|
+
end
|
32
|
+
|
33
|
+
|
25
34
|
== Note on Patches/Pull Requests
|
26
35
|
|
27
36
|
* Fork the project.
|
@@ -35,4 +44,4 @@ is running:
|
|
35
44
|
|
36
45
|
== Copyright
|
37
46
|
|
38
|
-
Copyright (c) 2010 ICE House AB. See LICENSE for details.
|
47
|
+
Copyright (c) 2010-11 ICE House AB. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,21 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "single_instance"
|
8
|
-
gem.summary = %Q{Ruby Gem that makes sure that only a single instance of a code block is running.}
|
9
|
-
gem.email = "dev+gemsupport@icehouse.se"
|
10
|
-
gem.homepage = "http://github.com/icehouse/single_instance"
|
11
|
-
gem.authors = ["David Vrensk", "Magnus Enarsson"]
|
12
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
13
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
-
end
|
15
|
-
Jeweler::GemcutterTasks.new
|
16
|
-
rescue LoadError
|
17
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
19
3
|
|
20
4
|
require 'rake/testtask'
|
21
5
|
Rake::TestTask.new(:test) do |test|
|
@@ -37,8 +21,8 @@ rescue LoadError
|
|
37
21
|
end
|
38
22
|
end
|
39
23
|
|
40
|
-
task :test => :check_dependencies
|
41
|
-
|
24
|
+
# task :test => :check_dependencies
|
25
|
+
#
|
42
26
|
task :default => :test
|
43
27
|
|
44
28
|
require 'rake/rdoctask'
|
data/lib/single_instance.rb
CHANGED
@@ -2,27 +2,33 @@ require 'tmpdir'
|
|
2
2
|
|
3
3
|
module SingleInstance
|
4
4
|
Blocker = Struct.new :pid, :started_at
|
5
|
+
|
5
6
|
class << self
|
6
7
|
|
7
8
|
def exclusive_non_blocking(name, &block)
|
8
9
|
lock_file = File.join(Dir::tmpdir, "single_instance_#{name}.pid")
|
9
|
-
|
10
|
+
begin
|
11
|
+
file = File.open(lock_file, "a+")
|
10
12
|
file.rewind
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
if file.flock(File::LOCK_EX|File::LOCK_NB)
|
14
|
+
file.truncate(0)
|
15
|
+
file.puts $$
|
16
|
+
file.puts Time.now.to_i
|
17
|
+
file.flush
|
18
|
+
if block_given?
|
17
19
|
yield nil
|
18
|
-
|
19
|
-
|
20
|
-
started_at = Time.at(file.readline.to_i)
|
21
|
-
yield Blocker.new(pid, started_at)
|
20
|
+
else
|
21
|
+
(@lock_files ||= []) << file
|
22
22
|
end
|
23
|
-
|
24
|
-
file.
|
23
|
+
elsif block_given? && block.arity == 1
|
24
|
+
pid = file.readline.to_i
|
25
|
+
started_at = Time.at(file.readline.to_i)
|
26
|
+
yield Blocker.new(pid, started_at)
|
27
|
+
else
|
28
|
+
false
|
25
29
|
end
|
30
|
+
ensure
|
31
|
+
file.close if block_given?
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/single_instance/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "single_instance"
|
6
|
+
s.version = SingleInstance::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["David Vrensk", "Magnus Enarsson"]
|
9
|
+
s.email = ["dev+gemsupport@icehouse.se"]
|
10
|
+
s.homepage = "http://github.com/icehouse/single_instance"
|
11
|
+
s.summary = %Q{Ruby Gem that makes sure that only a single instance of a code block or process is running.}
|
12
|
+
s.description = "SingleInstance uses an exclusive file lock to allow or block execution of code."
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "single_instance"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
s.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
22
|
+
s.require_path = 'lib'
|
23
|
+
end
|
@@ -42,6 +42,13 @@ class TestSingleInstance < Test::Unit::TestCase
|
|
42
42
|
assert @block_1
|
43
43
|
assert @block_2
|
44
44
|
end
|
45
|
+
|
46
|
+
context "without a block" do
|
47
|
+
should "create a lock that lasts until the process terminates" do
|
48
|
+
assert SingleInstance.exclusive_non_blocking(:blockless)
|
49
|
+
assert ! SingleInstance.exclusive_non_blocking(:blockless)
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
46
53
|
|
47
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: single_instance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- David Vrensk
|
@@ -10,36 +15,58 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date:
|
18
|
+
date: 2011-05-02 00:00:00 +02:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
version: 1.0.0
|
18
34
|
type: :development
|
19
|
-
|
20
|
-
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: thoughtbot-shoulda
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
21
41
|
requirements:
|
22
42
|
- - ">="
|
23
43
|
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
24
46
|
version: "0"
|
25
|
-
|
26
|
-
|
27
|
-
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: SingleInstance uses an exclusive file lock to allow or block execution of code.
|
50
|
+
email:
|
51
|
+
- dev+gemsupport@icehouse.se
|
28
52
|
executables: []
|
29
53
|
|
30
54
|
extensions: []
|
31
55
|
|
32
|
-
extra_rdoc_files:
|
33
|
-
|
34
|
-
- README.rdoc
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
35
58
|
files:
|
36
59
|
- .document
|
37
60
|
- .gitignore
|
61
|
+
- .rvmrc
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
38
64
|
- LICENSE
|
39
65
|
- README.rdoc
|
40
66
|
- Rakefile
|
41
|
-
- VERSION
|
42
67
|
- lib/single_instance.rb
|
68
|
+
- lib/single_instance/version.rb
|
69
|
+
- single_instance.gemspec
|
43
70
|
- test/helper.rb
|
44
71
|
- test/test_single_instance.rb
|
45
72
|
has_rdoc: true
|
@@ -47,29 +74,34 @@ homepage: http://github.com/icehouse/single_instance
|
|
47
74
|
licenses: []
|
48
75
|
|
49
76
|
post_install_message:
|
50
|
-
rdoc_options:
|
51
|
-
|
77
|
+
rdoc_options: []
|
78
|
+
|
52
79
|
require_paths:
|
53
80
|
- lib
|
54
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
55
83
|
requirements:
|
56
84
|
- - ">="
|
57
85
|
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
58
88
|
version: "0"
|
59
|
-
version:
|
60
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
61
91
|
requirements:
|
62
92
|
- - ">="
|
63
93
|
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 3
|
97
|
+
- 6
|
98
|
+
version: 1.3.6
|
66
99
|
requirements: []
|
67
100
|
|
68
|
-
rubyforge_project:
|
69
|
-
rubygems_version: 1.3.
|
101
|
+
rubyforge_project: single_instance
|
102
|
+
rubygems_version: 1.3.7
|
70
103
|
signing_key:
|
71
104
|
specification_version: 3
|
72
|
-
summary: Ruby Gem that makes sure that only a single instance of a code block is running.
|
73
|
-
test_files:
|
74
|
-
|
75
|
-
- test/test_single_instance.rb
|
105
|
+
summary: Ruby Gem that makes sure that only a single instance of a code block or process is running.
|
106
|
+
test_files: []
|
107
|
+
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|