mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-08-18 08:39:13 +02:00
global-functions: $ScriptLock: use a limit on lock...
... to make sure it does not lock forever.
This commit is contained in:
parent
7de3457f44
commit
0b4c1861cf
1 changed files with 6 additions and 4 deletions
|
@ -906,7 +906,7 @@
|
||||||
:set ScriptLock do={
|
:set ScriptLock do={
|
||||||
:local Script [ :tostr $1 ];
|
:local Script [ :tostr $1 ];
|
||||||
:local DoReturn $2;
|
:local DoReturn $2;
|
||||||
:local DoWait $3;
|
:local WaitMax ([ :tonum $3 ] * 10);
|
||||||
|
|
||||||
:global GetRandomNumber;
|
:global GetRandomNumber;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
|
@ -950,8 +950,10 @@
|
||||||
:local MyTicket [ $GetRandomNumber ];
|
:local MyTicket [ $GetRandomNumber ];
|
||||||
:set ($ScriptLockOrder->$Script) [ $AddTicket ($ScriptLockOrder->$Script) $MyTicket ];
|
:set ($ScriptLockOrder->$Script) [ $AddTicket ($ScriptLockOrder->$Script) $MyTicket ];
|
||||||
|
|
||||||
:while ($DoWait = true && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < $JobCount)) do={
|
:local WaitCount 0;
|
||||||
|
:while ($WaitMax > $WaitCount && (($ScriptLockOrder->$Script->0) != $MyTicket || [ :len ($ScriptLockOrder->$Script) ] < $JobCount)) do={
|
||||||
:delay 100ms;
|
:delay 100ms;
|
||||||
|
:set WaitCount ($WaitCount + 1);
|
||||||
:set JobCount [ :len [ / system script job find where script=$Script ] ];
|
:set JobCount [ :len [ / system script job find where script=$Script ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -961,8 +963,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
:set ($ScriptLockOrder->$Script) [ $RemoveTicket ($ScriptLockOrder->$Script) $MyTicket ];
|
:set ($ScriptLockOrder->$Script) [ $RemoveTicket ($ScriptLockOrder->$Script) $MyTicket ];
|
||||||
$LogPrintExit2 info $0 ("Script '" . $Script . "' started more than once... Aborting.") \
|
$LogPrintExit2 info $0 ("Script '" . $Script . "' started more than once" . [ $IfThenElse ($WaitCount > 0) \
|
||||||
[ $IfThenElse ($DoReturn = true) false true ];
|
" and timed out waiting for lock" "" ] . "... Aborting.") [ $IfThenElse ($DoReturn = true) false true ];
|
||||||
:return true;
|
:return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue