table of contents
AnyEvent::Processor(3pm) | User Contributed Perl Documentation | AnyEvent::Processor(3pm) |
NAME¶
AnyEvent::Processor - Base class to define an event-driven (AnyEvent) task that could periodically be interrupted by a watcher
VERSION¶
version 0.006
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();
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".
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.
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.
SEE ALSO¶
- AnyEvent::Processor::Converion
- AnyEvent::Processor::Watcher
AUTHOR¶
Frédéric Demians <f.demians@tamil.fr>
COPYRIGHT AND LICENSE¶
This software is Copyright (c) 2015 by Fréderic Demians.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
2022-06-06 | perl v5.34.0 |