Argon::Client - Client-side connection class for Argon systems
version 0.18
use Argon::Client; use AnyEvent; my $cv = AnyEvent->condvar; my $ar = Argon::Client->new( host => 'some.host.net', port => 1234, retry => 1, opened => $cv, ready => sub{}, failed => sub{}, closed => sub{}, notify => sub{}, ); $cv->recv; while (my $task = get_next_task) { $ar->process($task->class, $task->args, \&task_complete); } my $result = $ar->async(sub{ ... }); if ($result eq 'fnord') { ... }
Provides the client connection to an Argon network.
The hostname of the Argon::Manager serving as the entry point for the Argon network.
The port number for the Argon::Manager.
By default, when the network is at capacity, new tasks may be rejected, causing "result" in Argon::Message to croak. If retry is set, the Argon::Client will instead retry the task on a logarithmic backoff timer until the task is accepted by the manager.
retry
Argon::Client
A code ref that is triggered when the connection is initially opened.
A code ref that is triggered when the connection has been opened and the client is ready to begin sending tasks.
A code ref that is triggered when the connection fails. The value of $! is passed as an argument.
$!
A code ref that is triggered when the connection to the remote host is closed.
When tasks are created without a callback (see "process" in Argon::Client), the notify callback is used in its place. The Argon::Message reply is passed as an argument.
notify
Pings the Argon::Manager and calls the supplied callback with the manager's reply.
$ar->ping(sub{ my $reply = shift; ... });
Queues a task with the Ar manager. Accepts the name of a class accessible to the workers defining a new and run method, an array of arguments to be passed to new, and an optional code ref to be called when the task is complete. If not supplied, the "notify" in Argon::Client method will be called in its place.
new
run
$ar->queue('Task::Class', $args_list, sub{ my $reply = shift; ... });
If the Ar workers were started with --allow-eval and if the client process itself has $Argon::ALLOW_EVAL set to a true value, a code ref may be passed in place of a task class. The code ref will be serialized using Data::Dump::Streamer and has limited support for closures.
--allow-eval
$Argon::ALLOW_EVAL
$ar->process(sub{ ... }, $args_list, sub{ my $reply = shift; ... });
As an alternative to passing a callback or using a default callback, the async method returns a tied scalar that, when accessed, blocks until the result is available. Note that if the task resulted in an error, it is thrown when the async is fetched.
async
my $async = $ar->async(sub{ ... }, $arg_list); if ($async eq 'slood') { ... }
See Argon::Async.
Jeff Ober <sysread@fastmail.fm>
This software is copyright (c) 2017 by Jeff Ober.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Argon, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Argon
CPAN shell
perl -MCPAN -e shell install Argon
For more information on module installation, please visit the detailed CPAN module installation guide.