AnyEve...ocessor(3pm)

πŸ“¦
version 0.006 Β· 2 versions
  • 0.006 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.006 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– AnyEvent::Processor β€” bestie edition πŸ’–

okay so this is a Perl man page, section 3pm (that's "user contributed Perl documentation", iykyk), and it's literally all about a base class for building event-driven AnyEvent tasks that a watcher can interrupt every so often. Let's get into it 🫢


✨ NAME ✨

AnyEvent::Processor β€” the base class you extend to define an event-driven (AnyEvent) task that can, like, periodically be interrupted by a watcher. no cap, that's the whole vibe.

🌸 VERSION 🌸

version 0.006 β€” yeah it's giving vintage, and we love her for it πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

here's the whole vibe in code, verbatim, don't touch a single character:

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();
fr fr, we're monitoring fridges in this example and honestly? iconic. 🧊

πŸ¦‹ DESCRIPTION πŸ¦‹

A processor task built on this class handles anything that can be split up into processing clusters ✨. Each cluster gets processed one at a time, by calling the process() method. Then a count gets incremented at the end of each cluster. And by default, there's an AnyEvent::Processor::Watcher hanging out with the class, interrupting the processing every second so it can call "process_message". the way that just... happens automatically? obsessed 😭

πŸ’œ ATTRIBUTES πŸ’œ

🌈 verbose

Verbose mode! πŸ—£οΈ When you turn this on, an AnyEvent::Processor::Watcher gets automatically created, with a 1s timeout, and its action is sent directly to this class. And hey β€” you can build your own watcher by subclassing AnyEvent::Processor::Watcher if you're feeling creative πŸ’…

⭐ watcher

An AnyEvent::Processor::Watcher. that's it, that's the attribute 🫢

πŸ”₯ count

The number of items which have been processed. keep counting bestie, you're doing amazing ✨

πŸ’€ blocking

Is it a blocking task (not a task)? False by default. okay that description is a little cryptic but I'm just the messenger, and the fact is False by default πŸ’…

πŸ‘‘ METHODS πŸ‘‘

🌸 run

Run the process. go go go πŸƒβ€β™€οΈ

πŸ“ start_process

Something to do at the beginning of the process. your lil opening act ✨

πŸ’– start_message

Something to say about the process. It's called by the default watcher when verbose mode is enabled. By default, it just sends 'Start process...' to STDOUT. Your class can display a different message, or do something else entirely β€” like sending an email, or firing off a notification to a monitoring system like Nagios. multi-talented fr fr πŸ‘‘

🧚 process

Process something and increment count. Now listen β€” this method has to be surclassed (subclassed/overridden, in the original's own wording) by your class if you want to do something other than just incrementing the "count" attribute. so like, override it, bestie, don't just leave it there being basic πŸ’…

πŸŽ€ process_message

Say something about the process. Called by the default watcher (verbose mode) each 1s. By default, it just displays the "count" value. But your processor can display something other than just the number of processing clusters already processed β€” if your processor monitors the temperature of your fridge, you can display it... 🧊🌑️ the range?? unmatched.

🌈 end_process

Do something at the end of the process. the grand finale, the closing number ✨

πŸ’œ end_message

Say something at the end of the process. Called by the default watcher. a lil goodbye note 🫢

🌟 SEE ALSO 🌟

  • AnyEvent::Processor::Converion
  • AnyEvent::Processor::Watcher
(yes, Converion is spelled exactly like that in the original, and no, I will not be fixing it β€” I keep every detail, periodt πŸ’…)

🫢 AUTHOR 🫢

FrΓ©dΓ©ric Demians <f.demians@tamil.fr> β€” thank you for your service, king πŸ‘‘

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

and that's the whole page, bestie!! πŸ’– this was rendered with perl v5.34.0, dated 2022-06-06, from the AnyEve...ocessor(3pm) page (yes the title's truncated like that, it's giving mysterious, we keep it). now go forth and process those clusters βœ¨πŸ¦‹πŸŒΈ slay!!