Zing::Worker - Worker Process
Worker Process
package MyApp; use parent 'Zing::Worker'; sub handle { my ($name, $data) = @_; [$name, $data]; } sub perform { time; } sub queues { ['todos']; } sub receive { my ($self, $from, $data) = @_; [$from, $data]; } package main; my $myapp = MyApp->new; # $myapp->execute;
This package provides a Zing::Process which listens to one or more queues calls the handle method for each new message received. The standard process perform and receive methods operate as expected.
handle
perform
receive
This package inherits behaviors from:
Zing::Process
This package uses type constraints from:
Zing::Types
This package supports the following scenarios:
# given: synopsis $myapp->handle('todos', { todo => 'rebuild' });
The handle method is meant to be implemented by a subclass and is automatically invoked when a message is received from a defined queue.
# given: synopsis $myapp->perform;
The perform method is meant to be implemented by a subclass and is automatically invoked iteratively by the event-loop.
# given: synopsis $myapp->queues;
The queues method is meant to be implemented by a subclass and is automatically invoked when the process is executed.
# given: synopsis $myapp->receive($myapp->name, { status => 'ok' });
The receive method is meant to be implemented by a subclass and is automatically invoked iteratively by the event-loop.
This package has the following attributes:
on_handle(Maybe[CodeRef])
This attribute is read-only, accepts (Maybe[CodeRef]) values, and is optional.
(Maybe[CodeRef])
on_queues(Maybe[CodeRef])
This package implements the following methods:
handle(Str $queue, HashRef $data) : Any
The handle method, when not overloaded, executes the callback in the "on_handle" attribute for each new message available in any of the queues delcared.
my $worker = Zing::Worker->new( on_handle => sub { my ($self, $queue, $data) = @_; [$queue, $data]; }, ); $worker->handle('todos', {});
queues(Any @args) : ArrayRef[Str]
The queues method, when not overloaded, executes the callback in the "on_queues" attribute and expects a list of named queues to be processed.
my $worker = Zing::Worker->new( on_queues => sub { ['todos']; }, ); $worker->queues;
my $worker = Zing::Worker->new( on_queues => sub { my ($self, @queues) = @_; [@queues, 'other']; }, ); $worker->queues('todos-p1', 'todos-p2', 'todos-p3');
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To install Zing, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Zing
CPAN shell
perl -MCPAN -e shell install Zing
For more information on module installation, please visit the detailed CPAN module installation guide.