process_lock 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # ProcessLock
2
2
 
3
3
  A simple class to acquire and check process-id file based locks on a unix filesystem.
4
+ Can also be used to see if a process is already running or designate a master process when running concurrent applications.
4
5
 
5
- [![Build Status](https://travis-ci.org/ianheggie/ruby-process-lock.png?branch=master)](https://travis-ci.org/ianheggie/ruby-process-lock)
6
+ [![Build Status](https://travis-ci.org/ianheggie/process_lock.png?branch=master)](https://travis-ci.org/ianheggie/process_lock)
6
7
 
7
8
  ## Installation
8
9
 
@@ -21,7 +22,7 @@ Or install it yourself as:
21
22
  ## Usage
22
23
 
23
24
  Create an instance of ProcessLock with a filename as the lock.
24
- You may have more than one lock per process.
25
+ You may have more than one lock (with different names) per process.
25
26
 
26
27
  Methods:
27
28
  * acquire - Acquires a lock if it can. Returns true (or value of block if block is passed) if a lock was acquired, otherwise false.
@@ -33,11 +34,11 @@ Methods:
33
34
 
34
35
  Note:
35
36
  * locks don't stack - if we have already acquired the lock subsequent calls will reacquire the lock. releasing an already released lock will fail.
36
- * If Rails.root is defined then lock files will be put in tmp/pids, and have .pid appended if no extension is specified
37
+ * If Rails.root is defined then lock files without path separators (/) will be put in tmp/pids. If no extension is specified then .pid will be appended.
37
38
 
38
39
  To acquire a lock, do some work and then release it:
39
40
 
40
- pl = ProcessLock.new('tmp/name_of_lock.pid')
41
+ pl = ProcessLock.new('tmp/name_of_lock.lock')
41
42
 
42
43
  acquired = pl.acquire do
43
44
  puts "Do some work!"
@@ -53,74 +54,23 @@ To acquire a lock, do some work and then release it:
53
54
  puts "Do some work!"
54
55
  pl.release
55
56
 
57
+ To allow many worker processes to self organise and identify a leader process. (Simon and my implementation have diverged).
56
58
 
57
- Example:
58
-
59
- irb - run first
60
-
61
- >> require 'process_lock'
62
- => true
63
- >> Process.pid
64
- => 16568
65
- >> p = ProcessLock.new('tmp/example.tmp')
66
- => #<ProcessLock:0x00000001489c10 @filename="tmp/example.tmp">
67
- >> p.alive?
68
- => false
69
- >> p.owner?
70
- => false
71
- >> p.read
72
- => 0
73
-
74
- >> p.acquire!
59
+ IRB 1>>
60
+ pl = ProcessLock.new('example.tmp')
61
+ pl.acquire
75
62
  => true
63
+ pl.read
64
+ => "2435"
76
65
 
77
- >> p.alive?
78
- => true
79
- >> p.owner?
80
- => true
81
- >> p.read
82
- => 16568
83
- >> sleep(10)
84
- => 10
85
- >> p.release!
86
- => true
87
- >> p.alive?
88
- => false
89
- >> p.owner?
90
- => false
91
- >> p.read
92
- => 0
93
-
94
- 2nd irb, run after first has acquired the lock
95
-
96
- >> require 'process_lock'
97
- => true
98
- >> Process.pid
99
- => 16569
100
- >> q = ProcessLock.new('tmp/example.tmp')
101
- => #<ProcessLock:0x000000026e4090 @filename="tmp/example.tmp">
102
- >> q.alive?
103
- => true
104
- >> q.owner?
105
- => false
106
- >> q.read
107
- => 16568
108
-
109
- >> q.acquire!
110
- ProcessLock::AlreadyLocked: Unable to acquire lock
111
- from /home/ianh/Projects/Github/ruby-process-lock/lib/process_lock.rb:28:in `acquire!'
112
- from (irb):7
113
- from /home/ianh/.rbenv/versions/1.9.3-p484/bin/irb:12:in `<main>'
114
-
115
- >> q.alive?
116
- => true
117
- >> q.owner?
66
+ IRB 2>>
67
+ pl = ProcessLock.new('example.tmp')
68
+ pl.acquire
118
69
  => false
119
- >> q.read
120
- => 16568
121
- >>
70
+ pl.read
71
+ => "2435"
122
72
 
123
- example.tmp will contain the pid of the running process
73
+ example.tmp will contain the pid of the leader process
124
74
 
125
75
  ## Contributing
126
76
 
@@ -132,7 +82,7 @@ example.tmp will contain the pid of the running process
132
82
 
133
83
  ## License and contributions
134
84
 
135
- * Based on work Copyright (c) 2008 Simon Engledew, released under the MIT license.
136
- * Subsequent work by Ian Heggie: packaged into a gem, added tests and acquire method, fixed acquire so it didn't overwrite locks by other processes.
85
+ * Copyright (c) 2008 Simon Engledew, released under the MIT license: https://github.com/simon-engledew/ruby-process-lock .
86
+ * Subsequent work by Ian Heggie: packaged into a gem, added tests and acquire method, fixed some bugs.
137
87
  * See git log for other contributers
138
88
 
@@ -1,3 +1,3 @@
1
1
  class ProcessLock
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/process_lock.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["ian@heggie.biz"]
11
11
  spec.description = %q{A simple class to aquire and check process-id file based locks on a unix filesystem.}
12
12
  spec.summary = %q{Use process lock to see if a process is already running or designate a master process when running concurrent applications.}
13
- spec.homepage = "https://github.com/ianheggie/ruby-process-lock"
13
+ spec.homepage = "https://github.com/ianheggie/process_lock"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,77 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: process_lock
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Simon Engledew
14
9
  - Ian Heggie
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2014-02-14 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2014-02-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: bundler
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 9
30
- segments:
31
- - 1
32
- - 3
33
- version: "1.3"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.3'
34
23
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.3'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
40
34
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
48
39
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rspec
52
40
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
54
42
  none: false
55
- requirements:
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
56
52
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 2
61
- - 0
62
- version: "2.0"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
63
55
  type: :development
64
- version_requirements: *id003
65
- description: A simple class to aquire and check process-id file based locks on a unix filesystem.
66
- email:
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
63
+ description: A simple class to aquire and check process-id file based locks on a unix
64
+ filesystem.
65
+ email:
67
66
  - ian@heggie.biz
68
67
  executables: []
69
-
70
68
  extensions: []
71
-
72
69
  extra_rdoc_files: []
73
-
74
- files:
70
+ files:
75
71
  - .gitignore
76
72
  - .rspec
77
73
  - .travis.yml
@@ -85,40 +81,33 @@ files:
85
81
  - spec/process_lock_spec.rb
86
82
  - spec/run_example.sh
87
83
  - spec/spec_helper.rb
88
- homepage: https://github.com/ianheggie/ruby-process-lock
89
- licenses:
84
+ homepage: https://github.com/ianheggie/process_lock
85
+ licenses:
90
86
  - MIT
91
87
  post_install_message:
92
88
  rdoc_options: []
93
-
94
- require_paths:
89
+ require_paths:
95
90
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
91
+ required_ruby_version: !ruby/object:Gem::Requirement
97
92
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
105
- required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
98
  none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
114
103
  requirements: []
115
-
116
104
  rubyforge_project:
117
- rubygems_version: 1.8.6
105
+ rubygems_version: 1.8.23
118
106
  signing_key:
119
107
  specification_version: 3
120
- summary: Use process lock to see if a process is already running or designate a master process when running concurrent applications.
121
- test_files:
108
+ summary: Use process lock to see if a process is already running or designate a master
109
+ process when running concurrent applications.
110
+ test_files:
122
111
  - spec/other_process.sh
123
112
  - spec/process_lock_spec.rb
124
113
  - spec/run_example.sh