Class: Lepus::ProcessRegistry::FileBackend
- Inherits:
-
Object
- Object
- Lepus::ProcessRegistry::FileBackend
- Includes:
- Backend
- Defined in:
- lib/lepus/process_registry/file_backend.rb
Overview
File-based backend for process registry storage. Stores process data in a file using Marshal serialization. This is the default backend for apps not using the web dashboard.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add(process, metrics: {}) ⇒ Object
- #all ⇒ Object
- #clear ⇒ Object
- #count ⇒ Object
- #delete(process) ⇒ Object
- #exists?(id) ⇒ Boolean
- #find(id) ⇒ Object
-
#initialize(path: nil) ⇒ FileBackend
constructor
A new instance of FileBackend.
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Backend
Constructor Details
#initialize(path: nil) ⇒ FileBackend
Returns a new instance of FileBackend.
17 18 19 |
# File 'lib/lepus/process_registry/file_backend.rb', line 17 def initialize(path: nil) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/lepus/process_registry/file_backend.rb', line 15 def path @path end |
Instance Method Details
#add(process, metrics: {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/lepus/process_registry/file_backend.rb', line 29 def add(process, metrics: {}) transaction do |data| data[process.id] = process.to_h end end |
#all ⇒ Object
50 51 52 |
# File 'lib/lepus/process_registry/file_backend.rb', line 50 def all read.keys.map { |id| find(id) } end |
#clear ⇒ Object
60 61 62 63 64 |
# File 'lib/lepus/process_registry/file_backend.rb', line 60 def clear return unless path write({}) end |
#count ⇒ Object
54 55 56 57 58 |
# File 'lib/lepus/process_registry/file_backend.rb', line 54 def count return 0 unless path read.size end |
#delete(process) ⇒ Object
35 36 37 38 39 |
# File 'lib/lepus/process_registry/file_backend.rb', line 35 def delete(process) transaction do |data| data.delete(process.id) end end |
#exists?(id) ⇒ Boolean
46 47 48 |
# File 'lib/lepus/process_registry/file_backend.rb', line 46 def exists?(id) read.key?(id) end |
#find(id) ⇒ Object
41 42 43 44 |
# File 'lib/lepus/process_registry/file_backend.rb', line 41 def find(id) raw = read.fetch(id) { raise(Lepus::Process::NotFoundError.new(id)) } Lepus::Process.coerce(raw) end |
#start ⇒ Object
21 22 23 |
# File 'lib/lepus/process_registry/file_backend.rb', line 21 def start @path ||= Pathname.new(Dir.tmpdir).join("lepus_process_registry.store") end |
#stop ⇒ Object
25 26 27 |
# File 'lib/lepus/process_registry/file_backend.rb', line 25 def stop path.delete if path&.exist? end |