Class: Fractor::QueuePersister::YAMLPersister
- Defined in:
- lib/fractor/queue_persister.rb
Overview
YAML file persister. Stores queue state as a YAML document.
Instance Method Summary collapse
-
#clear ⇒ Boolean
Clear the YAML file.
-
#initialize(path) ⇒ YAMLPersister
constructor
Initialize a YAML persister.
-
#load ⇒ Array<Hash>?
Load work items from YAML file.
-
#save(items) ⇒ Boolean
Save work items to YAML file.
Constructor Details
#initialize(path) ⇒ YAMLPersister
Initialize a YAML persister.
130 131 132 |
# File 'lib/fractor/queue_persister.rb', line 130 def initialize(path) @path = path end |
Instance Method Details
#clear ⇒ Boolean
Clear the YAML file.
171 172 173 174 175 176 177 |
# File 'lib/fractor/queue_persister.rb', line 171 def clear File.delete(@path) if File.exist?(@path) true rescue StandardError => e warn "Failed to clear #{@path}: #{e.}" false end |
#load ⇒ Array<Hash>?
Load work items from YAML file.
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fractor/queue_persister.rb', line 154 def load return nil unless File.exist?(@path) yaml = File.read(@path) return nil if yaml.strip.empty? YAML.safe_load(yaml, permitted_classes: [Symbol, Hash, String, Integer, Float, TrueClass, FalseClass, NilClass]) rescue StandardError => e warn "Failed to load from #{@path}: #{e.}" nil end |
#save(items) ⇒ Boolean
Save work items to YAML file.
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/fractor/queue_persister.rb', line 138 def save(items) ensure_directory_exists serialized = items.map { |work| serialize_work(work) } yaml = YAML.dump(serialized) File.write(@path, yaml) true rescue StandardError => e warn "Failed to save to #{@path}: #{e.}" false end |