mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -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
|
property db_path = File.expand_path "~/mango/mango.db", home: true
|
||||||
|
|
||||||
@[YAML::Field(key: "scan_interval_minutes")]
|
@[YAML::Field(key: "scan_interval_minutes")]
|
||||||
property scan_interval = 5
|
property scan_interval : Int32 = 5
|
||||||
|
|
||||||
def self.load
|
def self.load
|
||||||
cfg_path = File.expand_path "~/.config/mango/config.yml", home: true
|
cfg_path = File.expand_path "~/.config/mango/config.yml", home: true
|
||||||
|
@ -142,13 +142,24 @@ class TitleInfo
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Library
|
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
|
# 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
|
@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
|
end
|
||||||
def get_title(name)
|
def get_title(name)
|
||||||
@titles.find { |t| t.title == name }
|
@titles.find { |t| t.title == name }
|
||||||
|
@ -4,7 +4,7 @@ require "./library"
|
|||||||
require "./storage"
|
require "./storage"
|
||||||
|
|
||||||
config = Config.load
|
config = Config.load
|
||||||
library = Library.new config.library_path
|
library = Library.new config.library_path, config.scan_interval
|
||||||
storage = Storage.new config.db_path
|
storage = Storage.new config.db_path
|
||||||
|
|
||||||
server = Server.new config, library, storage
|
server = Server.new config, library, storage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user