Method: MadeleineServer#start_snapshot_thread

Defined in:
app/models/wiki_service.rb

#start_snapshot_threadObject



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'app/models/wiki_service.rb', line 199

def start_snapshot_thread
  Thread.new(@server) {
    hours_since_last_snapshot = 0
    while true
      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'
          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