philiprehberger-lock_kit 0.5.0 → 0.6.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 +5 -0
- data/README.md +9 -0
- data/lib/philiprehberger/lock_kit/version.rb +1 -1
- data/lib/philiprehberger/lock_kit.rb +11 -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: c73f047a2d1e5c9452f0c9ee35ea25f7129211c150c37e81ab8d64685a1e4335
|
|
4
|
+
data.tar.gz: 037df68b9cdbeffa96ed4a7a356bbed7df5ec0038f82421095c221c2f8937151
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86041b9199af015a6a6be088a589447d8bf53d60d47daf3f16d1ec4a98541c858fb85f6d3b09772fad2150793dd215b1f2955db62f7184d2bbbb9c76bf2b94a0
|
|
7
|
+
data.tar.gz: e6524a26607e7c72305bcb462d038fe2897c9511646ac9ba9dc29ac35d4e8954950f95c113dab0e18615d9d5be07a01f292b429ae509e5f6c6731adda6d43d8c
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-05-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `LockKit.age(path)` — returns the age in seconds of an active lock based on its `acquired_at` metadata, or `nil` if not locked or metadata is missing.
|
|
14
|
+
|
|
10
15
|
## [0.5.0] - 2026-04-21
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -114,6 +114,14 @@ info = Philiprehberger::LockKit.owner('/tmp/my.lock')
|
|
|
114
114
|
# => { pid: 12345, hostname: 'web-01', acquired_at: 2026-03-28 12:00:00 +0000 }
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
+
### Lock Age
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
# Returns the age in seconds (Float) of an active lock, or nil if not locked
|
|
121
|
+
Philiprehberger::LockKit.age('/tmp/my.lock')
|
|
122
|
+
# => 12.34
|
|
123
|
+
```
|
|
124
|
+
|
|
117
125
|
### Lock Waiting with Callbacks
|
|
118
126
|
|
|
119
127
|
```ruby
|
|
@@ -173,6 +181,7 @@ Philiprehberger::LockKit.stale?('/tmp/my_worker.pid') # => true/false
|
|
|
173
181
|
| `.stale?(pid_file)` | Check if a PID file references a dead process |
|
|
174
182
|
| `.expired?(path)` | Check if a lock has expired based on its TTL |
|
|
175
183
|
| `.owner(path)` | Get lock owner metadata (pid, hostname, acquired_at) |
|
|
184
|
+
| `.age(path)` | Age in seconds of an active lock, or nil if not locked |
|
|
176
185
|
| `.break!(path, force: false)` | Break a lock (stale only by default, any with force) |
|
|
177
186
|
| `.rw_stats(path)` | Snapshot of a read-write lock as `{ readers:, write_locked: }` |
|
|
178
187
|
|
|
@@ -226,6 +226,17 @@ module Philiprehberger
|
|
|
226
226
|
nil
|
|
227
227
|
end
|
|
228
228
|
|
|
229
|
+
# Get the age in seconds of an active lock based on its `acquired_at` metadata
|
|
230
|
+
#
|
|
231
|
+
# @param path [String] path to the lock file or PID file
|
|
232
|
+
# @return [Float, nil] age in seconds, or nil if not locked or `acquired_at` is missing
|
|
233
|
+
def self.age(path)
|
|
234
|
+
data = owner(path)
|
|
235
|
+
return nil unless data && data[:acquired_at]
|
|
236
|
+
|
|
237
|
+
Time.now - data[:acquired_at]
|
|
238
|
+
end
|
|
239
|
+
|
|
229
240
|
# Force break a lock
|
|
230
241
|
#
|
|
231
242
|
# @param path [String] path to the lock file or 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.6.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-
|
|
11
|
+
date: 2026-05-07 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.
|