Argon

 view release on metacpan or  search on metacpan

bin/ar-worker  view on Meta::CPAN

#!perl

# PODNAME: worker
# ABSTRACT: Starts an Argon worker service


use strict;
use warnings;
use AnyEvent;
use Argon::Log;
use Argon::Worker;
use Getopt::Long::Descriptive;

my ($opt, $usage) = describe_options(
  'worker %o',
  ['key|k=s',      '(required) path to file containing encryption key', {required => 1}],
  ['capacity|c=i', '(required) max number of worker processes permitted', {required => 1, callbacks => {'positive int' => sub { shift > 0 }}}],
  ['mgr|m=s',      '(required) address of Argon manager service (e.g. some.host.com:4242)', {required => 1, callbacks => {'host:port' => sub { shift =~ /^.+?:\d+$/ }}}],
  ['allow-eval|a', '(optional) permit execution of serialized code (warning: this is a security risk if not running in a safe environment)'],
  ['verbose|v=i',  '(optional) level of verbosity (1 - 9; defaults to 5 [warn])', {default => 'warn'}],
  [],
  ['help|h',  'prints this help text and exits', {shortcircuit => 1}],
  ['usage|u', 'prints this help text and exits', {shortcircuit => 1}],
);

if ($opt->help) {
  print $usage->text;
  exit;
}

my ($mgr_host, $mgr_port) = split /:/, $opt->mgr;
unless ($mgr_host && $mgr_port) {
  warn "Expected format host:port for --mgr\n";
  print $usage->text;
  exit;
}

log_level $opt->verbose;
$Argon::ALLOW_EVAL = $opt->allow_eval ? 1 : 0;

my $cv      = AnyEvent->condvar;
my $sigint  = AnyEvent->signal(signal => 'INT' , cb => sub { log_info 'Caught SIGINT';  $cv->send });
my $sigterm = AnyEvent->signal(signal => 'TERM', cb => sub { log_info 'Caught SIGTERM'; $cv->send });

my $worker = Argon::Worker->new(
  keyfile  => $opt->key,
  capacity => $opt->capacity,
  mgr_host => $mgr_host,
  mgr_port => $mgr_port,
);

$worker->start;

$cv->recv;

exit 0;

__END__

=pod

=encoding UTF-8

=head1 NAME

worker - Starts an Argon worker service

=head1 VERSION

version 0.18

=head1 SYNOPSIS

  worker --mgr some.host.com:4242 --capacity 16

=head1 DESCRIPTION

Starts an Argon worker service. The worker will attempt to connect and register



( run in 0.995 second using v1.01-cache-2.11-cpan-437f7b0c052 )