mirror of https://github.com/octoleo/lsyncd.git
code cleanups
This commit is contained in:
parent
319681e7eb
commit
2f4dd3aa7e
101
default.lua
101
default.lua
|
@ -8,7 +8,8 @@
|
||||||
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
-- Authors: Axel Kittenberger <axkibe@gmail.com>
|
||||||
--============================================================================
|
--============================================================================
|
||||||
|
|
||||||
if default then
|
if default
|
||||||
|
then
|
||||||
error( 'default already loaded' )
|
error( 'default already loaded' )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -96,12 +97,25 @@ default.collect = function( agent, exitcode )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO synchronize with similar code before
|
-- TODO synchronize with similar code before
|
||||||
if not agent.isList and agent.etype == 'Init' then
|
if not agent.isList and agent.etype == 'Init'
|
||||||
if rc == 'ok' then
|
then
|
||||||
log('Normal', 'Startup of ',agent.source,' -> ',agent.target,' finished.')
|
if rc == 'ok'
|
||||||
|
then
|
||||||
|
log(
|
||||||
|
'Normal',
|
||||||
|
'Startup of ',
|
||||||
|
agent.source,
|
||||||
|
' -> ',
|
||||||
|
agent.target,
|
||||||
|
' finished.'
|
||||||
|
)
|
||||||
|
|
||||||
return 'ok'
|
return 'ok'
|
||||||
elseif rc == 'again' then
|
|
||||||
if settings('insist') then
|
elseif rc == 'again'
|
||||||
|
then
|
||||||
|
if settings('insist')
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Normal',
|
'Normal',
|
||||||
'Retrying startup of ',
|
'Retrying startup of ',
|
||||||
|
@ -151,20 +165,24 @@ default.collect = function( agent, exitcode )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if agent.isList then
|
if agent.isList
|
||||||
if rc == 'ok' then
|
then
|
||||||
|
if rc == 'ok'
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Normal',
|
'Normal',
|
||||||
'Finished a list after exitcode: ',
|
'Finished a list after exitcode: ',
|
||||||
exitcode
|
exitcode
|
||||||
)
|
)
|
||||||
elseif rc == 'again' then
|
elseif rc == 'again'
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Normal',
|
'Normal',
|
||||||
'Retrying a list after exitcode = ',
|
'Retrying a list after exitcode = ',
|
||||||
exitcode
|
exitcode
|
||||||
)
|
)
|
||||||
elseif rc == 'die' then
|
elseif rc == 'die'
|
||||||
|
then
|
||||||
log(
|
log(
|
||||||
'Error',
|
'Error',
|
||||||
'Failure with a list with exitcode = ',
|
'Failure with a list with exitcode = ',
|
||||||
|
@ -179,15 +197,52 @@ default.collect = function( agent, exitcode )
|
||||||
rc = 'die'
|
rc = 'die'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if rc == 'ok' then
|
if rc == 'ok'
|
||||||
log('Normal', 'Finished ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
|
then
|
||||||
elseif rc == 'again' then
|
log(
|
||||||
log('Normal', 'Retrying ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
|
'Normal',
|
||||||
elseif rc == 'die' then
|
'Finished ',
|
||||||
log('Error', 'Failure with ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
|
agent.etype,
|
||||||
|
' on ',
|
||||||
|
agent.sourcePath,
|
||||||
|
' = ',
|
||||||
|
exitcode
|
||||||
|
)
|
||||||
|
elseif rc == 'again'
|
||||||
|
then
|
||||||
|
log(
|
||||||
|
'Normal',
|
||||||
|
'Retrying ',
|
||||||
|
agent.etype,
|
||||||
|
' on ',
|
||||||
|
agent.sourcePath,
|
||||||
|
' = ',
|
||||||
|
exitcode
|
||||||
|
)
|
||||||
|
elseif rc == 'die'
|
||||||
|
then
|
||||||
|
log(
|
||||||
|
'Error',
|
||||||
|
'Failure with ',
|
||||||
|
agent.etype,
|
||||||
|
' on ',
|
||||||
|
agent.sourcePath,
|
||||||
|
' = ',
|
||||||
|
exitcode
|
||||||
|
)
|
||||||
else
|
else
|
||||||
log('Normal', 'Unknown exitcode "',exitcode,'" with ', agent.etype,
|
log(
|
||||||
' on ',agent.sourcePath,' = ',exitcode)
|
'Normal',
|
||||||
|
'Unknown exitcode "',
|
||||||
|
exitcode,
|
||||||
|
'" with ',
|
||||||
|
agent.etype,
|
||||||
|
' on ',
|
||||||
|
agent.sourcePath,
|
||||||
|
' = ',
|
||||||
|
exitcode
|
||||||
|
)
|
||||||
|
|
||||||
rc = 'die'
|
rc = 'die'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -202,16 +257,19 @@ end
|
||||||
--
|
--
|
||||||
default.init = function(event)
|
default.init = function(event)
|
||||||
local config = event.config
|
local config = event.config
|
||||||
|
|
||||||
local inlet = event.inlet
|
local inlet = event.inlet
|
||||||
|
|
||||||
-- user functions
|
-- user functions
|
||||||
-- calls a startup if given by user script.
|
-- calls a startup if given by user script.
|
||||||
if type(config.onStartup) == 'function' then
|
if type(config.onStartup) == 'function'
|
||||||
|
then
|
||||||
local startup = config.onStartup(event)
|
local startup = config.onStartup(event)
|
||||||
-- TODO honor some return codes of startup like "warmstart".
|
-- TODO honor some return codes of startup like "warmstart".
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.status == 'wait' then
|
if event.status == 'wait'
|
||||||
|
then
|
||||||
-- user script did not spawn anything
|
-- user script did not spawn anything
|
||||||
-- thus the blanket event is deleted again.
|
-- thus the blanket event is deleted again.
|
||||||
inlet.discardEvent(event)
|
inlet.discardEvent(event)
|
||||||
|
@ -356,7 +414,8 @@ default.prepare = function( config, level )
|
||||||
|
|
||||||
local gauge = config.checkgauge
|
local gauge = config.checkgauge
|
||||||
|
|
||||||
if not gauge then
|
if not gauge
|
||||||
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue