From 6578bed720e8914eb1b6ef12e54f38ecb77c3a9f Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Mon, 1 Aug 2005 05:02:52 +0000 Subject: [PATCH] Starting snapshot thread on first HTTP request (otherwise, --daemon option fails); ticket:48, ticket:198 --- app/controllers/application.rb | 8 ++++++-- app/models/wiki_service.rb | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 1e2af4e6..d97c51cd 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -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'] diff --git a/app/models/wiki_service.rb b/app/models/wiki_service.rb index c7f8d515..a48addc9 100644 --- a/app/models/wiki_service.rb +++ b/app/models/wiki_service.rb @@ -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