philiprehberger-lock_kit 0.4.0 → 0.5.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +3 -0
- data/lib/philiprehberger/lock_kit/read_write_lock.rb +10 -2
- data/lib/philiprehberger/lock_kit/version.rb +1 -1
- data/lib/philiprehberger/lock_kit.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd5f40b2057061170fc5913d9ac238f7070d3fb05025e9f5bffe2e321e3b240b
|
|
4
|
+
data.tar.gz: ece6023899b7329973758c48b3f7da96937e9cdc700ec4a11f0e572a7f9d4246
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b57abbeb1216f641fbe8d386425df778fd50a9aadc64be51f98df41e3f47409e6886c0bfe588cde71223b73a684c7da5c7e4c14996c30e66f70961d0fd8bec3
|
|
7
|
+
data.tar.gz: 4e85ef77b8c6c6bdb50f327a8ddf0841f19754e40ec20b1cfa52e69b7b5ef1127cf8426ed4c4f5e4584c2ff3e54bc13ed8905ab6cd5a15b68da83d7925966d81
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-04-21
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `ReadWriteLock#write_locked?` promoted to a public non-blocking query method
|
|
14
|
+
- `ReadWriteLock#stats` returning `{ readers:, write_locked: }` snapshot
|
|
15
|
+
- `LockKit.rw_stats(path)` module-level helper for the same snapshot without an instance
|
|
16
|
+
|
|
10
17
|
## [0.4.0] - 2026-04-15
|
|
11
18
|
|
|
12
19
|
### Added
|
data/README.md
CHANGED
|
@@ -174,6 +174,7 @@ Philiprehberger::LockKit.stale?('/tmp/my_worker.pid') # => true/false
|
|
|
174
174
|
| `.expired?(path)` | Check if a lock has expired based on its TTL |
|
|
175
175
|
| `.owner(path)` | Get lock owner metadata (pid, hostname, acquired_at) |
|
|
176
176
|
| `.break!(path, force: false)` | Break a lock (stale only by default, any with force) |
|
|
177
|
+
| `.rw_stats(path)` | Snapshot of a read-write lock as `{ readers:, write_locked: }` |
|
|
177
178
|
|
|
178
179
|
### `LockKit::FileLock`
|
|
179
180
|
|
|
@@ -208,6 +209,8 @@ Philiprehberger::LockKit.stale?('/tmp/my_worker.pid') # => true/false
|
|
|
208
209
|
| `#acquire_write(timeout: nil)` | Acquire exclusive write lock |
|
|
209
210
|
| `#release_write` | Release the write lock |
|
|
210
211
|
| `#reader_count` | Get current number of active readers |
|
|
212
|
+
| `#write_locked?` | Non-blocking check for an active write lock |
|
|
213
|
+
| `#stats` | Snapshot as `{ readers:, write_locked: }` |
|
|
211
214
|
|
|
212
215
|
## Development
|
|
213
216
|
|
|
@@ -126,8 +126,9 @@ module Philiprehberger
|
|
|
126
126
|
0
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
# Non-blocking check for whether a write lock is currently held.
|
|
130
|
+
#
|
|
131
|
+
# @return [Boolean]
|
|
131
132
|
def write_locked?
|
|
132
133
|
return false unless File.exist?(@write_lock_path)
|
|
133
134
|
|
|
@@ -143,6 +144,13 @@ module Philiprehberger
|
|
|
143
144
|
end
|
|
144
145
|
end
|
|
145
146
|
|
|
147
|
+
# Snapshot of the current lock state: readers and writer presence.
|
|
148
|
+
#
|
|
149
|
+
# @return [Hash] `{ readers: Integer, write_locked: Boolean }`
|
|
150
|
+
def stats
|
|
151
|
+
{ readers: reader_count, write_locked: write_locked? }
|
|
152
|
+
end
|
|
153
|
+
|
|
146
154
|
def increment_readers
|
|
147
155
|
update_reader_count(1)
|
|
148
156
|
end
|
|
@@ -126,6 +126,14 @@ module Philiprehberger
|
|
|
126
126
|
FileLock.new(path).locked?
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
+
# Snapshot of read-write lock state for `path` as `{ readers:, write_locked: }`.
|
|
130
|
+
#
|
|
131
|
+
# @param path [String] base path used with `with_read_lock` / `with_write_lock`
|
|
132
|
+
# @return [Hash] `{ readers: Integer, write_locked: Boolean }`
|
|
133
|
+
def self.rw_stats(path)
|
|
134
|
+
ReadWriteLock.new(path).stats
|
|
135
|
+
end
|
|
136
|
+
|
|
129
137
|
# Check if a PID file references a dead process
|
|
130
138
|
#
|
|
131
139
|
# @param pid_file [String] path to the PID file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-lock_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: File locks using flock and PID file locks with stale detection for coordinating
|
|
14
14
|
between processes. Timeout support and automatic cleanup.
|