Madeleine will check every hour if there are new commands in the log or 24 hours have passed since last snapshot, and take snapshot if either of these conditions is true
This commit is contained in:
parent
5daf352e68
commit
bf309d3fbd
2 changed files with 29 additions and 7 deletions
|
@ -79,7 +79,7 @@ class WikiController < ApplicationController
|
|||
end
|
||||
|
||||
def export_pdf
|
||||
file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}"
|
||||
file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}"
|
||||
file_path = WikiService.storage_path + file_name
|
||||
|
||||
export_web_to_tex(file_path + ".tex") unless FileTest.exists?(file_path + ".tex")
|
||||
|
@ -88,7 +88,7 @@ class WikiController < ApplicationController
|
|||
end
|
||||
|
||||
def export_tex
|
||||
file_name = "#{web.address}-tex-#{web.revised_on.strftime("%Y-%m-%d-%H-%M")}.tex"
|
||||
file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M')}.tex"
|
||||
file_path = WikiService.storage_path + file_name
|
||||
|
||||
export_web_to_tex(file_path) unless FileTest.exists?(file_path)
|
||||
|
|
|
@ -127,8 +127,8 @@ class WikiService
|
|||
end
|
||||
|
||||
class MadeleineServer
|
||||
SNAPSHOT_INTERVAL = 60 * 60 * 24 # Each day
|
||||
AUTOMATIC_SNAPSHOTS = true
|
||||
|
||||
attr_reader :storage_path
|
||||
|
||||
# Clears all the command_log and snapshot files located in the storage directory, so the
|
||||
# database is essentially dropped and recreated as blank
|
||||
|
@ -145,22 +145,44 @@ class MadeleineServer
|
|||
end
|
||||
|
||||
def initialize(service)
|
||||
@storage_path = service.storage_path
|
||||
@server = Madeleine::Automatic::AutomaticSnapshotMadeleine.new(service.storage_path,
|
||||
Madeleine::ZMarshal.new) {
|
||||
service.new
|
||||
}
|
||||
start_snapshot_thread if AUTOMATIC_SNAPSHOTS
|
||||
start_snapshot_thread
|
||||
end
|
||||
|
||||
def system
|
||||
@server.system
|
||||
end
|
||||
|
||||
def command_log_present?
|
||||
not Dir[storage_path + '/*.command_log'].empty?
|
||||
end
|
||||
|
||||
def start_snapshot_thread
|
||||
Thread.new(@server) {
|
||||
hours_since_last_snapshot = 0
|
||||
while true
|
||||
sleep(SNAPSHOT_INTERVAL)
|
||||
@server.take_snapshot
|
||||
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'
|
||||
@server.take_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
|
||||
|
|
Loading…
Reference in a new issue