mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
global-functions: $WaitForFile: use delay instead of iterations
This commit is contained in:
parent
b794d98cbb
commit
978c03131a
2 changed files with 7 additions and 6 deletions
|
@ -1214,19 +1214,20 @@
|
||||||
# wait for file to be available
|
# wait for file to be available
|
||||||
:set WaitForFile do={
|
:set WaitForFile do={
|
||||||
:local FileName [ :tostr $1 ];
|
:local FileName [ :tostr $1 ];
|
||||||
:local Iter [ :tonum $2 ];
|
:local WaitTime [ :totime $2 ];
|
||||||
|
|
||||||
:global CleanFilePath;
|
:global CleanFilePath;
|
||||||
:global EitherOr;
|
:global EitherOr;
|
||||||
|
|
||||||
:set FileName [ $CleanFilePath $FileName ];
|
:set FileName [ $CleanFilePath $FileName ];
|
||||||
:local I 0;
|
:local I 1;
|
||||||
|
:local Delay ([ :totime [ $EitherOr $WaitTime 2s ] ] / 20);
|
||||||
|
|
||||||
:while ([ :len [ /file/find where name=$FileName ] ] = 0) do={
|
:while ([ :len [ /file/find where name=$FileName ] ] = 0) do={
|
||||||
:if ($I > [ $EitherOr $Iter 20 ]) do={
|
:if ($I >= 20) do={
|
||||||
:return false;
|
:return false;
|
||||||
}
|
}
|
||||||
:delay 100ms;
|
:delay $Delay;
|
||||||
:set I ($I + 1);
|
:set I ($I + 1);
|
||||||
}
|
}
|
||||||
:return true;
|
:return true;
|
||||||
|
|
|
@ -103,7 +103,7 @@ $WaitFullyConnected;
|
||||||
$LogPrintExit2 info $0 ("Running command: " . $Text) false;
|
$LogPrintExit2 info $0 ("Running command: " . $Text) false;
|
||||||
:exec script=(":do {\n" . $Text . "\n} on-error={ :execute script=\":put\" file=" . $File . ".failed };" . \
|
:exec script=(":do {\n" . $Text . "\n} on-error={ :execute script=\":put\" file=" . $File . ".failed };" . \
|
||||||
":execute script=\":put\" file=" . $File . ".done") file=$File;
|
":execute script=\":put\" file=" . $File . ".done") file=$File;
|
||||||
:if ([ $WaitForFile ($File . ".done.txt") 200 ] = false) do={
|
:if ([ $WaitForFile ($File . ".done.txt") 20s ] = false) do={
|
||||||
:set State "The command did not finish, still running in background.\n\n";
|
:set State "The command did not finish, still running in background.\n\n";
|
||||||
}
|
}
|
||||||
:if ([ :len [ /file/find where name=($File . ".failed.txt") ] ] > 0) do={
|
:if ([ :len [ /file/find where name=($File . ".failed.txt") ] ] > 0) do={
|
||||||
|
|
Loading…
Reference in a new issue