libraries/madeleine_service.rb in Pimki-1.3.092 vs libraries/madeleine_service.rb in Pimki-1.4.092

- old
+ new

@@ -1,7 +1,8 @@ -require 'madeleine/automatic' require 'madeleine' +require 'madeleine/automatic' +require 'madeleine/zmarshal' require 'singleton' require 'yaml' class MadeleineService include Madeleine::Automatic::Interceptor @@ -15,43 +16,41 @@ def storage_path=(storage_path) @@storage_path = storage_path end - def clean_storage - MadeleineServer.clean_storage(self) - end - def instance @system = MadeleineServer.new(self).system if @system.nil? @system end def restart - clean_storage + MadeleineServer.clean_storage(self) @system = MadeleineServer.new(self).system end end end class MadeleineServer - SNAPSHOT_INTERVAL = 60 * 60 * 24 # seconds * minutes * hours => Each day + SNAPSHOT_INTERVAL = 30 * 60 * 24 # Each day AUTOMATIC_SNAPSHOTS = true # Clears all the command_log and snapshot files located in the storage directory, so the - # database is essentially dropped and recreated as blank + # database is essentially dropped and recreated as blank. Used in tests. def self.clean_storage(service) - begin - Dir.foreach(service.storage_path) do |file| - File.delete(service.storage_path + File::SEPARATOR + file) if file =~ /(command_log|snapshot)$/ - end - rescue - Dir.mkdir(service.storage_path) + require 'fileutils' + if (File.directory?(service.storage_path)) + FileUtils.rm_rf(Dir[service.storage_path + '/*.command_log']) + FileUtils.rm_rf(Dir[service.storage_path + '/*.snapshot']) + else + FileUtils.mkdir_p(service.storage_path) end end def initialize(service) - @server = Madeleine::Automatic::AutomaticSnapshotMadeleine.new(service.storage_path) { service.new } + marshaller = Madeleine::ZMarshal.new() + @server = Madeleine::Automatic::AutomaticSnapshotMadeleine.new(service.storage_path, + marshaller) { service.new } start_snapshot_thread if AUTOMATIC_SNAPSHOTS end def system @server.system \ No newline at end of file