Class: MadeleineServer
- Inherits:
-
Object
- Object
- MadeleineServer
- Defined in:
- app/models/wiki_service.rb
Instance Attribute Summary collapse
-
#storage_path ⇒ Object
readonly
Returns the value of attribute storage_path.
Class Method Summary collapse
-
.clean_storage(service) ⇒ Object
Clears all the command_log and snapshot files located in the storage directory, so the database is essentially dropped and recreated as blank.
Instance Method Summary collapse
- #command_log_present? ⇒ Boolean
-
#initialize(service) ⇒ MadeleineServer
constructor
A new instance of MadeleineServer.
- #snapshot ⇒ Object
- #start_snapshot_thread ⇒ Object
- #system ⇒ Object
Constructor Details
#initialize(service) ⇒ MadeleineServer
Returns a new instance of MadeleineServer.
186 187 188 189 190 191 192 193 |
# File 'app/models/wiki_service.rb', line 186 def initialize(service) @storage_path = service.storage_path @server = Madeleine::Automatic::AutomaticSnapshotMadeleine.new(service.storage_path, Madeleine::ZMarshal.new) { service.new } start_snapshot_thread end |
Instance Attribute Details
#storage_path ⇒ Object (readonly)
Returns the value of attribute storage_path.
170 171 172 |
# File 'app/models/wiki_service.rb', line 170 def storage_path @storage_path end |
Class Method Details
.clean_storage(service) ⇒ Object
Clears all the command_log and snapshot files located in the storage directory, so the database is essentially dropped and recreated as blank
174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/models/wiki_service.rb', line 174 def self.clean_storage(service) begin Dir.foreach(service.storage_path) do |file| if file =~ /(command_log|snapshot)$/ File.delete(File.join(service.storage_path, file)) end end rescue Dir.mkdir(service.storage_path) end end |
Instance Method Details
#command_log_present? ⇒ Boolean
195 196 197 |
# File 'app/models/wiki_service.rb', line 195 def command_log_present? not Dir[storage_path + '/*.command_log'].empty? end |
#snapshot ⇒ Object
199 200 201 |
# File 'app/models/wiki_service.rb', line 199 def snapshot @server.take_snapshot end |
#start_snapshot_thread ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'app/models/wiki_service.rb', line 203 def start_snapshot_thread Thread.new(@server) { hours_since_last_snapshot = 0 while true begin hours_since_last_snapshot += 1 # Take a snapshot if there is a command log, or 24 hours # have passed since the last snapshot if command_log_present? or hours_since_last_snapshot >= 24 ActionController::Base.logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}] " + 'Taking a Madeleine snapshot' snapshot hours_since_last_snapshot = 0 end sleep(1.hour) rescue => e ActionController::Base.logger.error(e) # wait for a minute (not to spoof the log with the same error) # and go back into the loop, to keep trying sleep(1.minute) ActionController::Base.logger.info("Retrying to save a snapshot") end end } end |
#system ⇒ Object
229 230 231 |
# File 'app/models/wiki_service.rb', line 229 def system @server.system end |