logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

AnyEvent::Processor - Base class to define an event-driven (AnyEvent) task that could periodically be

Attributes

verbose
       Verbose mode. In this mode an AnyEvent::Processor::Watcher is automatically created, with a 1s timeout,
       and action directly sent to this class. You can create your own watcher subclassing
       AnyEvent::Processor::Watcher.

   watcher
       An AnyEvent::Processor::Watcher.

   count
       Number of items which have been processed.

   blocking
       Is it a blocking task (not a task). False by default.

Author

       Frédéric Demians <f.demians@tamil.fr>

Description

       A processor task based on this class process anything that can be divided into processing clusters. Each
       cluster is processed one by one by calling the process() method. A count is incremented at the end of
       each cluster. By default, a AnyEvent::Processor::Watcher is associated with the class, interrupting the
       processing each second for calling "process_message".

Methods

run
       Run the process.

   start_process
       Something to do at beginning of the process.

   start_message
       Something to say about the process. Called by default watcher when verbose mode is enabled. By default,
       just send to STDOUT 'Start process...'. Your class can display another message, or do something else,
       like sending an email, or a notification to a monitoring system like Nagios.

   process
       Process something and increment count. This method has to be surclassed by you class if you want to do
       someting else than incrementing the "count" attribute.

   process_message
       Say something about the process. Called by default watcher (verbose mode) each 1s. By default, just
       display the "count" value. Your processor can display something else than just the number of processing
       clusters already processed.  If your processor monitor the temperature of your fridge, you can display
       it...

   end_process
       Do something at the end of the process.

   end_message
       Say something at the end of the process. Called by default watcher.

Name

       AnyEvent::Processor - Base class to define an event-driven (AnyEvent) task that could periodically be
       interrupted by a watcher

See Also

       •   AnyEvent::Processor::Converion

       •   AnyEvent::Processor::Watcher

Synopsis

         package FridgeMonitoring;

         use Moose;
         extends 'AnyEvent::Processor';
         use TemperatureSensor;

         has sensors => (is => 'rw', isa => 'ArrayRef[TemperatureSensor]');
         has min => (is => 'rw', isa => 'Int', default => '10');
         has max => (is => 'rw', isa => 'Int', default => '20');

         sub process {
             my $self = shift;

             my @failed;
             for my $sensor ( @{$self->sensors} ) {
                 next if $self->sensor->temperature >= $self->min &&
                         $self->sensor->temperature <= $self->max;
                 push @failed, $sensor;
             }
             if ( @failed ) {
                 # Send an email to someone with the list of failed fridges
             }
         }

         sub process_message {
             my $self = shift;
             say "[", $self->count, "] Fridges testing";
         }

       package Main;

       use FridgeMonitoring;

       my $processor = FridgeMonitoring->new(
           sensors => # Get a list of fridge sensors from somewhere
           min => 0,
           max => 40, ); $processor->run();

Version

       version 0.006

See Also