Mercurial Hosting > luan
changeset 1368:5225cd6ed478
add Lucene schedule_backups_to
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 18 Jun 2019 21:56:53 -0600 |
parents | 836e00bf7ce2 |
children | 709f7498a363 |
files | src/luan/modules/lucene/Lucene.luan |
diffstat | 1 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/lucene/Lucene.luan Tue Jun 18 16:27:03 2019 -0600 +++ b/src/luan/modules/lucene/Lucene.luan Tue Jun 18 21:56:53 2019 -0600 @@ -10,10 +10,16 @@ local uri = Io.uri or error() local String = require "luan:String.luan" local matches = String.matches or error() +local Thread = require "luan:Thread.luan" +local schedule = Thread.schedule or error() +local run_for_backup = Thread.run_for_backup or error() +local Time = require "luan:Time.luan" local Rpc = require "luan:Rpc.luan" local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" local NumberFieldParser = require "java:luan.lib.queryparser.NumberFieldParser" local SaneQueryParser = require "java:luan.lib.queryparser.SaneQueryParser" +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "Lucene" local Lucene = {} @@ -138,6 +144,23 @@ end ) end + function index.schedule_backups_to(backup_dir,repeating_delay) + local lucene_dir = uri("file:"..index.dir) + local function backup() + if backup_dir.last_modified() < lucene_dir.last_modified() then + run_for_backup(function() + index.backup_to(backup_dir) + logger.info "backup" + end) + end + end + schedule( backup, { + repeating_delay = repeating_delay or Time.period{minutes=10} + run_on_close = true + daemon = true + } ) + end + function index.zip(zip_file) index.snapshot( function(dir_path,file_names) zip_file.delete()