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. # Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base 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 after_filter :remember_location
# For injecting a different wiki model implementation. Intended for use in tests # For injecting a different wiki model implementation. Intended for use in tests
@ -34,6 +34,10 @@ class ApplicationController < ActionController::Base
end end
end end
def check_snapshot_thread
WikiService.check_snapshot_thread
end
def connect_to_model def connect_to_model
@action_name = @params['action'] || 'index' @action_name = @params['action'] || 'index'
@web_name = @params['web'] @web_name = @params['web']

View file

@ -153,6 +153,11 @@ class WikiService
@madeleine.snapshot @madeleine.snapshot
end 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 end
def initialize def initialize
@ -185,7 +190,7 @@ class MadeleineServer
Madeleine::ZMarshal.new) { Madeleine::ZMarshal.new) {
service.new service.new
} }
start_snapshot_thread @snapshoot_thread_running = false
end end
def command_log_present? def command_log_present?
@ -196,7 +201,12 @@ class MadeleineServer
@server.take_snapshot @server.take_snapshot
end end
def check_snapshot_thread
start_snapshot_thread unless @snapshoot_thread_running
end
def start_snapshot_thread def start_snapshot_thread
@snapshoot_thread_running = true
Thread.new(@server) { Thread.new(@server) {
hours_since_last_snapshot = 0 hours_since_last_snapshot = 0
while true while true