From baa83945fcb07286de4d107058ae7ed043b2deff Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Sun, 28 Sep 2014 17:12:04 +0200 Subject: [PATCH] Try to save the last line parsed line when squid-analyzer is interrupted to avoid load twice the same data after restarting. Thanks to Michael Gauthier for the report. --- SquidAnalyzer.pm | 19 +++++++++++++------ squid-analyzer | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/SquidAnalyzer.pm b/SquidAnalyzer.pm index c68f0ea..a086e16 100644 --- a/SquidAnalyzer.pm +++ b/SquidAnalyzer.pm @@ -467,6 +467,18 @@ sub manage_queue_size return $child_count; } +sub save_current_line +{ + my $self = shift; + + if ($self->{end_time}) { + my $current = new IO::File; + $current->open(">$self->{Output}/SquidAnalyzer.current") or $self->localdie("FATAL: Can't write to file $self->{Output}/SquidAnalyzer.current, $!\n"); + print $current "$self->{end_time}\t$self->{end_offset}"; + $current->close; + } +} + sub parseFile { my ($self) = @_; @@ -621,12 +633,7 @@ sub parseFile } # Set the current start time into history file - if ($self->{end_time}) { - my $current = new IO::File; - $current->open(">$self->{Output}/SquidAnalyzer.current") or $self->localdie("FATAL: Can't write to file $self->{Output}/SquidAnalyzer.current, $!\n"); - print $current "$self->{end_time}\t$self->{end_offset}"; - $current->close; - } + $self->save_current_line(); # Force reordering and unique sorting of data files my $child_count = 0; diff --git a/squid-analyzer b/squid-analyzer index 3c1bb4f..1bd92ba 100644 --- a/squid-analyzer +++ b/squid-analyzer @@ -103,6 +103,9 @@ sub terminate $sa->{terminate} = 1; + # Save last parse line + $sa->save_current_line(); + # Wait for all child processes to die except for the logger my $kid = 0; do {