Daemonise
view release on metacpan or search on metacpan
examples/template.rabbit view on Meta::CPAN
#!/usr/bin/env perl
use Modern::Perl;
use experimental 'smartmatch';
use Daemonise;
use Getopt::Long;
my $pid;
my $debug;
my $conf = '/etc/daemonise/bunny.conf';
my $foreground;
GetOptions(
"debug|d" => \$debug,
"config|c=s" => \$conf,
"pidfile|p=s" => \$pid,
"foreground|f" => \$foreground,
) or die;
my $d = Daemonise->new();
$d->debug(1) if $debug;
$d->debug(1) if ($d->hostname =~ m/devel/);
$d->foreground(1) if $foreground;
$d->pid_file($pid) if $pid;
$d->config_file($conf);
$d->configure;
$d->load_plugin('RabbitMQ');
$d->load_plugin('CouchDB');
$d->load_plugin('JobQueue');
$d->load_plugin('Graphite'); # or $d->load_plugin('Riemann');
$d->load_plugin('Event');
$d->load_plugin('HipChat');
$d->load_plugin('PagerDuty');
$d->load_plugin('Paralleliser');
$d->load_plugin('KyotoTycoon'); # or $d->load_plugin('Redis');
# do not bind to any rabbitMQ queue
$d->is_worker(0);
# do not bind to additional admin queues
$d->admin_queue(0);
# hooks come only with JobQueue plugin
$d->hooks(
action => \&action,
default => \&action,
);
$d->start;
# alternatively start() takes a custom code reference if using hooks is not
# possible. using hooks is the preferred way though.
# $d->start(\&action);
sub action {
my ($msg) = @_;
# do stuff here
my $data = $msg->{data}->{options};
## JobQueue plugin calls ##
#
( run in 0.827 second using v1.01-cache-2.11-cpan-437f7b0c052 )