2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 22:56:34 +00:00

fhem.pl: reorg delayedshutdown (Forum #109755)

git-svn-id: https://svn.fhem.de/fhem/trunk@21573 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2020-04-01 16:26:14 +00:00
parent 5220f9ff74
commit d5d68807f7

View File

@ -1761,6 +1761,16 @@ CancelDelayedShutdown($)
delete($delayedShutdowns{$d});
}
sub
DoDelayedShutdown($)
{
my ($hash) = @_;
return CommandShutdown($hash->{cl},$hash->{param},undef,1,$hash->{exitValue})
if(!keys %delayedShutdowns ||
$hash->{waitingFor}++ >= $hash->{maxShutdownDelay});
InternalTimer(gettimeofday()+1, "DoDelayedShutdown", $hash, 0);
}
sub
DelayedShutdown($$$)
{
@ -1771,22 +1781,15 @@ DelayedShutdown($$$)
$delayedShutdowns{$d} = 1 if(CallFn($d, "DelayedShutdownFn", $defs{$d}));
}
return 0 if(!keys %delayedShutdowns);
my $waitingFor = 0;
my $maxShutdownDelay = AttrVal("global", "maxShutdownDelay", 10);
my $checkList;
my $maxShutdownDelay = AttrVal("global", "maxShutdownDelay", 10);
Log 1, "Server shutdown delayed due to ".join(",", keys %delayedShutdowns).
" for max $maxShutdownDelay sec";
DoTrigger("global", "DELAYEDSHUTDOWN", 1);
$checkList = sub()
{
return CommandShutdown($cl, $param, undef, 1, $exitValue)
if(!keys %delayedShutdowns || $waitingFor++ >= $maxShutdownDelay);
InternalTimer(gettimeofday()+1, $checkList, undef, 0);
};
$checkList->();
DoDelayedShutdown(
{ cl=>$cl, param=>$param, exitValue=>$exitValue,
waitingFor=>0, maxShutdownDelay=>$maxShutdownDelay } );
return 1;
}