Mercurial Hosting > luan
comparison src/luan/modules/lucene/Lucene.luan @ 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 |
comparison
equal
deleted
inserted
replaced
1367:836e00bf7ce2 | 1368:5225cd6ed478 |
---|---|
8 local Html = require "luan:Html.luan" | 8 local Html = require "luan:Html.luan" |
9 local Io = require "luan:Io.luan" | 9 local Io = require "luan:Io.luan" |
10 local uri = Io.uri or error() | 10 local uri = Io.uri or error() |
11 local String = require "luan:String.luan" | 11 local String = require "luan:String.luan" |
12 local matches = String.matches or error() | 12 local matches = String.matches or error() |
13 local Thread = require "luan:Thread.luan" | |
14 local schedule = Thread.schedule or error() | |
15 local run_for_backup = Thread.run_for_backup or error() | |
16 local Time = require "luan:Time.luan" | |
13 local Rpc = require "luan:Rpc.luan" | 17 local Rpc = require "luan:Rpc.luan" |
14 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" | 18 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" |
15 local NumberFieldParser = require "java:luan.lib.queryparser.NumberFieldParser" | 19 local NumberFieldParser = require "java:luan.lib.queryparser.NumberFieldParser" |
16 local SaneQueryParser = require "java:luan.lib.queryparser.SaneQueryParser" | 20 local SaneQueryParser = require "java:luan.lib.queryparser.SaneQueryParser" |
21 local Logging = require "luan:logging/Logging.luan" | |
22 local logger = Logging.logger "Lucene" | |
17 | 23 |
18 | 24 |
19 local Lucene = {} | 25 local Lucene = {} |
20 | 26 |
21 Lucene.instances = {} | 27 Lucene.instances = {} |
136 backup_file.link_to(lucene_file) | 142 backup_file.link_to(lucene_file) |
137 end | 143 end |
138 end ) | 144 end ) |
139 end | 145 end |
140 | 146 |
147 function index.schedule_backups_to(backup_dir,repeating_delay) | |
148 local lucene_dir = uri("file:"..index.dir) | |
149 local function backup() | |
150 if backup_dir.last_modified() < lucene_dir.last_modified() then | |
151 run_for_backup(function() | |
152 index.backup_to(backup_dir) | |
153 logger.info "backup" | |
154 end) | |
155 end | |
156 end | |
157 schedule( backup, { | |
158 repeating_delay = repeating_delay or Time.period{minutes=10} | |
159 run_on_close = true | |
160 daemon = true | |
161 } ) | |
162 end | |
163 | |
141 function index.zip(zip_file) | 164 function index.zip(zip_file) |
142 index.snapshot( function(dir_path,file_names) | 165 index.snapshot( function(dir_path,file_names) |
143 zip_file.delete() | 166 zip_file.delete() |
144 local zip_path = zip_file.canonical().to_string() | 167 local zip_path = zip_file.canonical().to_string() |
145 local dir = uri("file:"..dir_path) | 168 local dir = uri("file:"..dir_path) |