diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 70e199c414..fa4d6fa176 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2013-03-13 Ramon Novoa + + * lib/PandoraFMS/Tools.pm: Added support for ranges to server cron + modules. + + * lib/PandoraFMS/ProducerConsumerServer.pm: Update queue stats after + queuing new new modules. + 2013-03-11 Vanessa Gil * util/pandora_revent.pl: Addapted to API's function diff --git a/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm b/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm index ed55d77640..8cfe20c58c 100644 --- a/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm +++ b/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm @@ -113,9 +113,6 @@ sub data_producer ($$$$$) { # Get pending tasks my @tasks = &{$self->{'_producer'}}($self); - # Update queue size for statistics - $self->setQueueSize (scalar @{$task_queue}); - foreach my $task (@tasks) { $sem->down; @@ -132,6 +129,9 @@ sub data_producer ($$$$$) { $sem->up; } + # Update queue size for statistics + $self->setQueueSize (scalar @{$task_queue}); + threads->yield; sleep ($pa_config->{'server_threshold'}); } diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index c0f6ca8272..5d8bfaa415 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -41,6 +41,7 @@ our @ISA = ("Exporter"); our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( + cron_get_closest_in_range cron_next_execution cron_next_execution_date pandora_daemonize @@ -1071,14 +1072,19 @@ sub cron_next_execution ($) { # Get day of the week and month from cron config my ($mday, $wday) = (split (/\s/, $cron))[2, 4]; - # Get current time + # Get current time and day of the week my $cur_time = time(); + my $cur_wday = (localtime ($cur_time))[6]; - # Any day of the way + # Any day of the week if ($wday eq '*') { my $nex_time = cron_next_execution_date ($cron, $cur_time); return $nex_time - time(); } + # A range? + else { + $wday = cron_get_closest_in_range ($cur_wday, $wday); + } # A specific day of the week my $count = 0; @@ -1125,6 +1131,12 @@ sub cron_next_execution_date ($$) { } my ($cur_min, $cur_hour, $cur_mday, $cur_mon, $cur_year) = (localtime ($cur_time))[1, 2, 3, 4, 5]; + # Parse intervals + $min = cron_get_closest_in_range ($cur_min, $min); + $hour = cron_get_closest_in_range ($cur_hour, $hour); + $mday = cron_get_closest_in_range ($cur_mday, $mday); + $mon = cron_get_closest_in_range ($cur_mon, $mon); + # Get first next date candidate from cron configuration my ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = ($min, $hour, $mday, $mon, $cur_year); @@ -1190,6 +1202,31 @@ sub cron_next_execution_date ($$) { return $cur_time + 300; } +############################################################################### +# Returns the closest number to the target inside the given range (including +# the target itself). +############################################################################### +sub cron_get_closest_in_range ($$) { + my ($target, $range) = @_; + + # Not a range + if ($range !~ /(\d+)\-(\d+)/) { + return $range; + } + + # Search the closes number to the target in the given range + my $range_start = $1; + my $range_end = $2; + + # Outside the range + if ($target <= $range_start || $target > $range_end) { + return $range_start; + } + + # Inside the range + return $target; +} + # End of function declaration # End of defined Code