mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-07 10:50:51 +00:00
fixing encapsulated delays
This commit is contained in:
parent
4005c2899b
commit
d8b565ae02
79
lsyncd.lua
79
lsyncd.lua
|
@ -518,10 +518,19 @@ local Delay = ( function
|
||||||
local mt = { }
|
local mt = { }
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Key to native table
|
-- Secret key to native table
|
||||||
--
|
--
|
||||||
local k_nt = { }
|
local k_nt = { }
|
||||||
|
|
||||||
|
local assignAble =
|
||||||
|
{
|
||||||
|
dpos = true,
|
||||||
|
etype = true,
|
||||||
|
path = true,
|
||||||
|
path2 = true,
|
||||||
|
status = true,
|
||||||
|
}
|
||||||
|
|
||||||
--
|
--
|
||||||
-- On accessing a nil index.
|
-- On accessing a nil index.
|
||||||
--
|
--
|
||||||
|
@ -542,9 +551,9 @@ local Delay = ( function
|
||||||
k, -- key value to assign to
|
k, -- key value to assign to
|
||||||
v -- value to assign
|
v -- value to assign
|
||||||
)
|
)
|
||||||
if not t[ k_nt ][ k ]
|
if not assignAble[ k ]
|
||||||
then
|
then
|
||||||
error( 'Cannot assign new values to Delays' )
|
error( 'Cannot assign new key "' .. k .. '" to Delay' )
|
||||||
end
|
end
|
||||||
|
|
||||||
t[ k_nt ][ k ] = v
|
t[ k_nt ][ k ] = v
|
||||||
|
@ -560,13 +569,15 @@ local Delay = ( function
|
||||||
)
|
)
|
||||||
self[ k_nt ].status = 'block'
|
self[ k_nt ].status = 'block'
|
||||||
|
|
||||||
|
local blocks
|
||||||
|
|
||||||
if not self[ k_nt ].blocks
|
if not self[ k_nt ].blocks
|
||||||
then
|
then
|
||||||
blocks = { }
|
blocks = { }
|
||||||
|
|
||||||
self[ k_nt ].blocks = blocks
|
self[ k_nt ].blocks = blocks
|
||||||
else
|
else
|
||||||
blocks = self[ k_nt ]
|
blocks = self[ k_nt ].blocks
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert( blocks, delay )
|
table.insert( blocks, delay )
|
||||||
|
@ -596,6 +607,7 @@ local Delay = ( function
|
||||||
alarm = alarm,
|
alarm = alarm,
|
||||||
path = path,
|
path = path,
|
||||||
path2 = path2,
|
path2 = path2,
|
||||||
|
status = 'wait'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2295,8 +2307,10 @@ local Sync = ( function
|
||||||
--
|
--
|
||||||
-- Returns the soonest alarm for this Sync.
|
-- Returns the soonest alarm for this Sync.
|
||||||
--
|
--
|
||||||
local function getAlarm( self )
|
local function getAlarm
|
||||||
|
(
|
||||||
|
self
|
||||||
|
)
|
||||||
if self.processes:size( ) >= self.config.maxProcesses
|
if self.processes:size( ) >= self.config.maxProcesses
|
||||||
then
|
then
|
||||||
return false
|
return false
|
||||||
|
@ -2313,7 +2327,6 @@ local Sync = ( function
|
||||||
return d.alarm
|
return d.alarm
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- nothing to spawn
|
-- nothing to spawn
|
||||||
|
@ -2323,7 +2336,6 @@ local Sync = ( function
|
||||||
--
|
--
|
||||||
-- Gets all delays that are not blocked by active delays.
|
-- Gets all delays that are not blocked by active delays.
|
||||||
--
|
--
|
||||||
--
|
|
||||||
local function getDelays
|
local function getDelays
|
||||||
(
|
(
|
||||||
self, -- the sync
|
self, -- the sync
|
||||||
|
@ -3053,12 +3065,7 @@ local Inotify = ( function
|
||||||
(
|
(
|
||||||
path -- absolute path of directory to observe
|
path -- absolute path of directory to observe
|
||||||
)
|
)
|
||||||
log(
|
log( 'Function', 'Inotify.addWatch( ', path, ' )' )
|
||||||
'Function',
|
|
||||||
'Inotify.addWatch( ',
|
|
||||||
path,
|
|
||||||
' )'
|
|
||||||
)
|
|
||||||
|
|
||||||
if not Syncs.concerns(path)
|
if not Syncs.concerns(path)
|
||||||
then
|
then
|
||||||
|
@ -3832,12 +3839,7 @@ local StatusFile = ( function
|
||||||
(
|
(
|
||||||
timestamp
|
timestamp
|
||||||
)
|
)
|
||||||
log(
|
log( 'Function', 'write( ', timestamp, ' )' )
|
||||||
'Function',
|
|
||||||
'write( ',
|
|
||||||
timestamp,
|
|
||||||
' )'
|
|
||||||
)
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- takes care not write too often
|
-- takes care not write too often
|
||||||
|
@ -4035,7 +4037,10 @@ local lastReportedWaiting = false
|
||||||
--
|
--
|
||||||
-- Logs a backtrace
|
-- Logs a backtrace
|
||||||
--
|
--
|
||||||
function runner.callError( message )
|
function runner.callError
|
||||||
|
(
|
||||||
|
message
|
||||||
|
)
|
||||||
log('Error', 'in Lua: ', message )
|
log('Error', 'in Lua: ', message )
|
||||||
|
|
||||||
-- prints backtrace
|
-- prints backtrace
|
||||||
|
@ -4093,6 +4098,8 @@ end
|
||||||
function runner.cycle(
|
function runner.cycle(
|
||||||
timestamp -- the current kernel time (in jiffies)
|
timestamp -- the current kernel time (in jiffies)
|
||||||
)
|
)
|
||||||
|
log( 'Function', 'cycle( ', timestamp, ' )' )
|
||||||
|
|
||||||
if lsyncdStatus == 'fade'
|
if lsyncdStatus == 'fade'
|
||||||
then
|
then
|
||||||
if processCount > 0
|
if processCount > 0
|
||||||
|
@ -4117,7 +4124,8 @@ function runner.cycle(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if lsyncdStatus ~= 'run' then
|
if lsyncdStatus ~= 'run'
|
||||||
|
then
|
||||||
error( 'runner.cycle() called while not running!' )
|
error( 'runner.cycle() called while not running!' )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4126,9 +4134,8 @@ function runner.cycle(
|
||||||
-- if possibly. But only let Syncs invoke actions if
|
-- if possibly. But only let Syncs invoke actions if
|
||||||
-- not at global limit
|
-- not at global limit
|
||||||
--
|
--
|
||||||
if
|
if not uSettings.maxProcesses
|
||||||
not uSettings.maxProcesses or
|
or processCount < uSettings.maxProcesses
|
||||||
processCount < uSettings.maxProcesses
|
|
||||||
then
|
then
|
||||||
local start = Syncs.getRound( )
|
local start = Syncs.getRound( )
|
||||||
|
|
||||||
|
@ -4136,7 +4143,9 @@ function runner.cycle(
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
local s = Syncs.get( ir )
|
local s = Syncs.get( ir )
|
||||||
|
|
||||||
s:invokeActions( timestamp )
|
s:invokeActions( timestamp )
|
||||||
|
|
||||||
ir = ir + 1
|
ir = ir + 1
|
||||||
|
|
||||||
if ir > Syncs.size( )
|
if ir > Syncs.size( )
|
||||||
|
@ -4650,7 +4659,10 @@ end
|
||||||
-- true ... immediate action
|
-- true ... immediate action
|
||||||
-- times ... the alarm time (only read if number is 1)
|
-- times ... the alarm time (only read if number is 1)
|
||||||
--
|
--
|
||||||
function runner.getAlarm( )
|
function runner.getAlarm
|
||||||
|
( )
|
||||||
|
|
||||||
|
log( 'Function', 'getAlarm( )' )
|
||||||
|
|
||||||
if lsyncdStatus ~= 'run'
|
if lsyncdStatus ~= 'run'
|
||||||
then
|
then
|
||||||
|
@ -4662,7 +4674,10 @@ function runner.getAlarm( )
|
||||||
--
|
--
|
||||||
-- Checks if 'a' is sooner than the 'alarm' up-value.
|
-- Checks if 'a' is sooner than the 'alarm' up-value.
|
||||||
--
|
--
|
||||||
local function checkAlarm( a )
|
local function checkAlarm
|
||||||
|
(
|
||||||
|
a
|
||||||
|
)
|
||||||
if a == nil
|
if a == nil
|
||||||
then
|
then
|
||||||
error('got nil alarm')
|
error('got nil alarm')
|
||||||
|
@ -4686,12 +4701,12 @@ function runner.getAlarm( )
|
||||||
-- checks all syncs for their earliest alarm,
|
-- checks all syncs for their earliest alarm,
|
||||||
-- but only if the global process limit is not yet reached.
|
-- but only if the global process limit is not yet reached.
|
||||||
--
|
--
|
||||||
if
|
if not uSettings.maxProcesses
|
||||||
not uSettings.maxProcesses or
|
or processCount < uSettings.maxProcesses
|
||||||
processCount < uSettings.maxProcesses
|
|
||||||
then
|
then
|
||||||
for _, s in Syncs.iwalk( ) do
|
for _, s in Syncs.iwalk( )
|
||||||
checkAlarm( s:getAlarm ( ))
|
do
|
||||||
|
checkAlarm( s:getAlarm( ) )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log(
|
log(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user