mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
- periodic scan
This commit is contained in:
parent
26bb49fab5
commit
d9129ad58f
@ -13,7 +13,7 @@ class Config
|
||||
property db_path = File.expand_path "~/mango/mango.db", home: true
|
||||
|
||||
@[YAML::Field(key: "scan_interval_minutes")]
|
||||
property scan_interval = 5
|
||||
property scan_interval : Int32 = 5
|
||||
|
||||
def self.load
|
||||
cfg_path = File.expand_path "~/.config/mango/config.yml", home: true
|
||||
|
@ -142,13 +142,24 @@ class TitleInfo
|
||||
end
|
||||
|
||||
class Library
|
||||
JSON.mapping dir: String, titles: Array(Title)
|
||||
JSON.mapping dir: String, titles: Array(Title), scan_interval: Int32
|
||||
|
||||
def initialize(@dir)
|
||||
def initialize(@dir, @scan_interval)
|
||||
# explicitly initialize @titles to bypass the compiler check. it will
|
||||
# be filled with actuall Titles in the `scan` call below
|
||||
# be filled with actual Titles in the `scan` call below
|
||||
@titles = [] of Title
|
||||
scan
|
||||
|
||||
return scan if @scan_interval < 1
|
||||
spawn do
|
||||
loop do
|
||||
start = Time.local
|
||||
puts "#{start} Starting periodic scan"
|
||||
scan
|
||||
ms = (Time.local - start).total_milliseconds
|
||||
puts "Scanned #{@titles.size} titles in #{ms}ms"
|
||||
sleep @scan_interval * 60
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_title(name)
|
||||
@titles.find { |t| t.title == name }
|
||||
|
@ -4,7 +4,7 @@ require "./library"
|
||||
require "./storage"
|
||||
|
||||
config = Config.load
|
||||
library = Library.new config.library_path
|
||||
library = Library.new config.library_path, config.scan_interval
|
||||
storage = Storage.new config.db_path
|
||||
|
||||
server = Server.new config, library, storage
|
||||
|
Loading…
x
Reference in New Issue
Block a user