Daemonise
view release on metacpan or search on metacpan
examples/workflow.rabbit view on Meta::CPAN
#!/usr/bin/env perl
use Modern::Perl;
use Daemonise;
use Getopt::Long;
# PODNAME: workflow.rabbit
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('JobQueue');
$d->is_worker(1);
$d->dont_log_worker;
$d->start(\&process);
sub process {
my ($msg) = @_;
my $command = $msg->{meta}->{workflow} || $msg->{data}->{command};
# make sure meta->workflow always exists from now on
$msg->{meta}->{workflow} = $command
unless exists $msg->{meta}->{workflow}
and defined $msg->{meta}->{workflow};
unless ($command) {
$msg->{error} = "workflow parameter missing";
$d->update_job($msg);
return $msg;
}
$d->couchdb->db('workflow');
my $wf = $d->couchdb->get_view({
view => 'workflow/name',
opts => { key => $command },
});
unless ($wf and exists $wf->{$command}) {
$msg->{error} = "Could not find a workflow for [$command]";
$d->update_job($msg);
return $msg;
}
my $path = $wf->{$command};
my $next_hop;
( run in 0.661 second using v1.01-cache-2.11-cpan-437f7b0c052 )