comparison src/luan/modules/lucene/Lucene.luan @ 1408:5b8f76e26ab7

remove old backups
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 24 Sep 2019 15:02:33 -0600
parents 9882c053d26f
children c7f9dd062eda
comparison
equal deleted inserted replaced
1407:1979cff9aad2 1408:5b8f76e26ab7
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" 13 local Thread = require "luan:Thread.luan"
14 local schedule = Thread.schedule or error() 14 local schedule = Thread.schedule or error()
15 local run_in_lock = Thread.run_in_lock or error() 15 local run_in_lock = Thread.run_in_lock or error()
16 local backup_read_lock = Thread.backup_read_lock or error()
17 local Time = require "luan:Time.luan" 16 local Time = require "luan:Time.luan"
18 local Rpc = require "luan:Rpc.luan" 17 local Rpc = require "luan:Rpc.luan"
19 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" 18 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
20 local NumberFieldParser = require "java:goodjava.queryparser.NumberFieldParser" 19 local NumberFieldParser = require "java:goodjava.queryparser.NumberFieldParser"
21 local SaneQueryParser = require "java:goodjava.queryparser.SaneQueryParser" 20 local SaneQueryParser = require "java:goodjava.queryparser.SaneQueryParser"
149 backup_file.link_to(lucene_file) 148 backup_file.link_to(lucene_file)
150 end 149 end
151 end ) 150 end )
152 end 151 end
153 152
154 function index.schedule_backups_to(backup_dir,repeating_delay)
155 local lucene_dir = index.dir
156 local function backup()
157 if backup_dir.last_modified() < lucene_dir.last_modified() then
158 run_in_lock(backup_read_lock, index.backup_to,backup_dir)
159 logger.info "backup"
160 end
161 end
162 schedule( backup, {
163 repeating_delay = repeating_delay or Time.period{minutes=10}
164 } )
165 end
166
167 function index.zip(zip_file) 153 function index.zip(zip_file)
168 index.snapshot( function(dir_path,file_names) 154 index.snapshot( function(dir_path,file_names)
169 zip_file.delete() 155 zip_file.delete()
170 local zip_path = zip_file.canonical().to_string() 156 local zip_path = zip_file.canonical().to_string()
171 local dir = uri("file:"..dir_path) 157 local dir = uri("file:"..dir_path)
218 end 204 end
219 205
220 return index 206 return index
221 end 207 end
222 208
223 function Lucene.recover(index_dir,restore_dir)
224 if not index_dir.exists() and restore_dir.exists() then
225 index_dir.mkdir()
226 for _, child in ipairs(restore_dir.children()) do
227 index_dir.child(child.name()).link_to(child)
228 end
229 logger.error "recovered"
230 end
231 end
232
233 return Lucene 209 return Lucene