mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-13 14:43:09 +00:00
This commit is contained in:
parent
43be580976
commit
86596fe7bb
49
lsyncd.lua
49
lsyncd.lua
@ -193,7 +193,6 @@ end)()
|
|||||||
-- Holds information about one observed directory inclusively subdirs.
|
-- Holds information about one observed directory inclusively subdirs.
|
||||||
--
|
--
|
||||||
local Sync = (function()
|
local Sync = (function()
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Syncs that have no name specified get an incremental default name
|
-- Syncs that have no name specified get an incremental default name
|
||||||
--
|
--
|
||||||
@ -260,18 +259,36 @@ local Sync = (function()
|
|||||||
table.insert(delays, newd)
|
table.insert(delays, newd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-----
|
||||||
|
-- Return the nearest alarm for this Sync.
|
||||||
|
--
|
||||||
|
local function getAlarm(self)
|
||||||
|
-- first checks if more processses could be spawned
|
||||||
|
if self.processes:size() >= self.config.maxProcesses then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.delays[1] then
|
||||||
|
return self.delays[1].alarm
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-- Creates a new Sync
|
-- Creates a new Sync
|
||||||
--
|
--
|
||||||
local function new(config)
|
local function new(config)
|
||||||
local s = {
|
local s = {
|
||||||
|
-- TODO document.
|
||||||
config = config,
|
config = config,
|
||||||
delays = CountArray.new(),
|
delays = CountArray.new(),
|
||||||
delayname = {},
|
delayname = {},
|
||||||
source = config.source,
|
source = config.source,
|
||||||
processes = CountArray.new(),
|
processes = CountArray.new(),
|
||||||
|
|
||||||
|
-- functions
|
||||||
delay = delay,
|
delay = delay,
|
||||||
|
getAlarm = getAlarm,
|
||||||
}
|
}
|
||||||
-- provides a default name if needed
|
-- provides a default name if needed
|
||||||
if not config.name then
|
if not config.name then
|
||||||
@ -1003,21 +1020,27 @@ end
|
|||||||
--
|
--
|
||||||
function lsyncd_get_alarm()
|
function lsyncd_get_alarm()
|
||||||
local alarm = false
|
local alarm = false
|
||||||
for _, s in Syncs.iwalk() do
|
|
||||||
-- TODO better handling of stati.
|
----
|
||||||
if s.delays[1] and
|
-- checks if current nearest alarm or a is earlier
|
||||||
s.processes:size() < s.config.maxProcesses then
|
--
|
||||||
if alarm then
|
local function checkAlarm(a)
|
||||||
alarm = lsyncd.earlier(alarm, s.delays[1].alarm)
|
if not a then
|
||||||
else
|
return
|
||||||
alarm = s.delays[1].alarm
|
end
|
||||||
end
|
if not alarm then
|
||||||
|
alarm = a
|
||||||
|
else
|
||||||
|
alarm = lsyncd.earlier(alarm, a)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local sa = StatusFile.getAlarm()
|
|
||||||
if sa then
|
-- checks all syncs for their earliest alarm
|
||||||
alarm = (alarm and lsyncd.earlier(sa, alarm)) or sa
|
for _, s in Syncs.iwalk() do
|
||||||
|
checkAlarm(s:getAlarm())
|
||||||
end
|
end
|
||||||
|
-- checks if a statusfile write has been delayed
|
||||||
|
checkAlarm(StatusFile.getAlarm())
|
||||||
|
|
||||||
log("Debug", "lysncd_get_alarm returns: ",alarm)
|
log("Debug", "lysncd_get_alarm returns: ",alarm)
|
||||||
return alarm
|
return alarm
|
||||||
|
Loading…
Reference in New Issue
Block a user