Sha256: fe3afc169d678d9fa8a1f3cf89661e1f483593909c1e1b349a49d2c958cc425e
Contents?: true
Size: 1.67 KB
Versions: 2
Compression:
Stored size: 1.67 KB
Contents
require 'madeleine' require 'madeleine/automatic' require 'madeleine/zmarshal' require 'singleton' require 'yaml' class MadeleineService include Madeleine::Automatic::Interceptor @@storage_path = self.name.downcase + "_storage" class << self def storage_path @@storage_path end def storage_path=(storage_path) @@storage_path = storage_path end def instance @system = MadeleineServer.new(self).system if @system.nil? @system end def restart MadeleineServer.clean_storage(self) @system = MadeleineServer.new(self).system end end end class MadeleineServer 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. Used in tests. def self.clean_storage(service) 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) 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 end def start_snapshot_thread Thread.new(@server) { while true sleep(SNAPSHOT_INTERVAL) @server.take_snapshot end } end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
Pimki-1.4.092 | libraries/madeleine_service.rb |
instiki-0.9.2 | libraries/madeleine_service.rb |