Starting snapshot thread on first HTTP request (otherwise, --daemon option fails); ticket:48, ticket:198

This commit is contained in:
Alexey Verkhovsky 2005-08-01 05:02:52 +00:00
parent adc6b005d5
commit 6578bed720
2 changed files with 17 additions and 3 deletions

View file

@ -2,7 +2,7 @@
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
before_filter :set_utf8_http_header, :connect_to_model
before_filter :set_utf8_http_header, :connect_to_model, :check_snapshot_thread
after_filter :remember_location
# For injecting a different wiki model implementation. Intended for use in tests
@ -22,7 +22,7 @@ class ApplicationController < ActionController::Base
def authorized?
@web.nil? ||
@web.password.nil? ||
@web.password.nil? ||
cookies['web_address'] == @web.password ||
password_check(@params['password'])
end
@ -34,6 +34,10 @@ class ApplicationController < ActionController::Base
end
end
def check_snapshot_thread
WikiService.check_snapshot_thread
end
def connect_to_model
@action_name = @params['action'] || 'index'
@web_name = @params['web']

View file

@ -152,6 +152,11 @@ class WikiService
def snapshot
@madeleine.snapshot
end
def check_snapshot_thread
# @madeleine may not be initialised in unit tests, and in such case there is no need to do anything
@madeleine.check_snapshot_thread unless @madeleine.nil?
end
end
@ -185,7 +190,7 @@ class MadeleineServer
Madeleine::ZMarshal.new) {
service.new
}
start_snapshot_thread
@snapshoot_thread_running = false
end
def command_log_present?
@ -196,7 +201,12 @@ class MadeleineServer
@server.take_snapshot
end
def check_snapshot_thread
start_snapshot_thread unless @snapshoot_thread_running
end
def start_snapshot_thread
@snapshoot_thread_running = true
Thread.new(@server) {
hours_since_last_snapshot = 0
while true