NAME

Argon::Client - Client-side connection class for Argon systems

VERSION

version 0.18

SYNOPSIS

  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') {
    ...
  }

DESCRIPTION

Provides the client connection to an Argon network.

ATTRIBUTES

host

The hostname of the Argon::Manager serving as the entry point for the Argon network.

port

The port number for the Argon::Manager.

retry

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.

opened

A code ref that is triggered when the connection is initially opened.

ready

A code ref that is triggered when the connection has been opened and the client is ready to begin sending tasks.

failed

A code ref that is triggered when the connection fails. The value of $! is passed as an argument.

closed

A code ref that is triggered when the connection to the remote host is closed.

notify

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.

METHODS

ping

Pings the Argon::Manager and calls the supplied callback with the manager's reply.

  $ar->ping(sub{ my $reply = shift; ... });

queue

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.

  $ar->queue('Task::Class', $args_list, sub{
    my $reply = shift;
    ...
  });

process

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.

  $ar->process(sub{ ... }, $args_list, sub{
    my $reply = shift;
    ...
  });

async

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.

  my $async = $ar->async(sub{ ... }, $arg_list);

  if ($async eq 'slood') {
    ...
  }

See Argon::Async.

AUTHOR

Jeff Ober <sysread@fastmail.fm>

COPYRIGHT AND LICENSE

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.