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
permalink #initialize(service) ⇒ MadeleineServer
Returns a new instance of MadeleineServer.
182 183 184 185 186 187 188 189 |
# File 'app/models/wiki_service.rb', line 182 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
permalink #storage_path ⇒ Object (readonly)
Returns the value of attribute storage_path.
166 167 168 |
# File 'app/models/wiki_service.rb', line 166 def storage_path @storage_path end |
Class Method Details
permalink .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
170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/models/wiki_service.rb', line 170 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
permalink #command_log_present? ⇒ Boolean
191 192 193 |
# File 'app/models/wiki_service.rb', line 191 def command_log_present? not Dir[storage_path + '/*.command_log'].empty? end |
permalink #snapshot ⇒ Object
[View source]
195 196 197 |
# File 'app/models/wiki_service.rb', line 195 def snapshot @server.take_snapshot end |
permalink #start_snapshot_thread ⇒ Object
[View source]
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'app/models/wiki_service.rb', line 199 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 |
permalink #system ⇒ Object
[View source]
225 226 227 |
# File 'app/models/wiki_service.rb', line 225 def system @server.system end |