From 3368f94c1a96b871e060c45c9656a2ec841a2d76 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 8 Aug 2019 14:38:27 -0400 Subject: [PATCH] Add code to handleDelay to cancel identical delayed actions. Fixes #2619 (#2681) --- scripts/zmtrigger.pl.in | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/zmtrigger.pl.in b/scripts/zmtrigger.pl.in index 28ea6cde5..eda7b2e36 100644 --- a/scripts/zmtrigger.pl.in +++ b/scripts/zmtrigger.pl.in @@ -266,12 +266,11 @@ while (1) { Debug('Checking for timed actions'); my $now = time(); foreach my $action_time ( sort( grep { $_ < $now } @action_times ) ) { - Info("Found actions expiring at $action_time"); + Info("Found " . scalar @{$actions{$action_time}} . "actions expiring at $action_time"); foreach my $action ( @{$actions{$action_time}} ) { my $connection = $action->{connection}; - my $message = $action->{message}; - Info("Found action '$message'"); - handleMessage($connection, $message); + Info("Found action '$$action{message}'"); + handleMessage($connection, $$action{message}); } delete $actions{$action_time}; } @@ -443,6 +442,21 @@ sub handleDelay { my $action_text = shift; my $action_time = time()+$delay; + + # Need to check and cancel previous actions. See issue #2619 + foreach my $a_time ( keys %actions ) { + if ( $a_time <= $action_time ) { + for ( my $i = 0; $i < @{$actions{$a_time}}; $i ++ ) { + my $action = $actions{$a_time}[$i]; + if ( $$action{message} eq $action_text ) { + Info("Found duplicate action '$$action{message}' at $a_time, cancelling it"); + splice @{$actions{$a_time}}, $i, 1; + } + } # end foreach action + delete $actions{$a_time} if !@{$actions{$a_time}}; + } # end if + } # end foreach action_time + my $action_array = $actions{$action_time}; if ( !$action_array ) { $action_array = $actions{$action_time} = [];