Asgaroth has asked for the wisdom of the Perl Monks concerning the following question:
sub compress_logs() { $compress_process_manager = new Parallel::ForkManager(4) ; while( my $filename = $archive_queue->take ) { if ( defined ($filename) ) { my $pid = $compress_process_manager->start and next ; next unless -e $filename; next unless -e $filename . ".sum"; next if -e $filename . ".gz"; $message_queue->put(RUN_LOG, "Recieved $filename For Compr +ession"); $message_queue->put(RUN_LOG, "Begining Compression Of $fil +ename"); $message_queue->put(RUN_LOG, "Reading $filename Into Memor +y"); my $string = ''; open(FH, "<$filename") or die "Could not open $filename ($ +{OS_ERROR})"; binmode(FH); while(<FH>) { $string .= ${ARG} }; close(FH); $message_queue->put(RUN_LOG, "Completed Reading $filename +Into Memory"); $message_queue->put(RUN_LOG, "Compressing $filename Memory + Image"); my $dest = Compress::Zlib::memGzip($string) ; $message_queue->put(RUN_LOG, "Completed Compressing $filen +ame Memory Image"); $message_queue->put(RUN_LOG, "Flushing $filename Memory Im +age To Disk"); open(FH, ">$filename.gz") or die "Could not open $filename +.gz (${OS_ERROR})"; binmode(FH); print FH $dest; close(FH); undef($string); $message_queue->put(RUN_LOG, "Completed Flushing $filename + Memory Image To Disk"); $message_queue->put(RUN_LOG, "Removing $filename After Com +pression"); unlink($filename); $message_queue->put(RUN_LOG, "Completed Removing $filename + After Compression"); $message_queue->put(RUN_LOG, "Removing $filename.sum After + Compression"); unlink($filename . ".sum"); $message_queue->put(RUN_LOG, "Completed Removing $filename +.sum After Compression"); $message_queue->put(RUN_LOG, "Completed Compression Of $fi +lename"); $compress_process_manager->finish ; }; }; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Thread::Conveyor and Parallel::ForkManager
by BrowserUk (Patriarch) on Aug 09, 2004 at 08:16 UTC | |
by Asgaroth (Novice) on Aug 09, 2004 at 09:22 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2004 at 09:42 UTC | |
by Asgaroth (Novice) on Aug 09, 2004 at 10:03 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2004 at 11:08 UTC | |
| |
by perrin (Chancellor) on Aug 09, 2004 at 12:25 UTC | |
|
Re: Using Thread::Conveyor and Parallel::ForkManager
by pearlie (Sexton) on Aug 09, 2004 at 08:14 UTC |