Catalyst-Engine-JobQueue-POE

 view release on metacpan or  search on metacpan

lib/Catalyst/Helper/JobQueue/POE.pm  view on Meta::CPAN

package Catalyst::Helper::JobQueue::POE;

use strict;
use warnings;

use version; our $VERSION = qv('0.0.1');

our $CATALYST_SCRIPT_GEN = 30;

=head1 NAME

Catalyst::Helper::JobQueue::POE - create files for running a job queue

=head1 SYNOPSIS

  script/create.pl JobQueue::POE

=head1 DESCRIPTION

This helper creates the required files for a job queue. It creates a JobQueue
runner script in your application's F<script> directory and a F<crontab>
configuration file in your applications root directory. 

After editing your configuration file, you can start the job queue by
executing the runner script.

=head1 METHODS

=head2 mk_stuff

Generates a JobQueue runner script and a sample crontab file.

=head1 AUTHOR

Gruen Christian-Rolf <kiki@bdsro.org>

=head1 SEE ALSO

L<Catalyst>,L<Catalyst::Engine::JobQueue::POE>

=cut

sub mk_stuff
{
    my ( $self, $helper, @args ) = @_;

    $self->_mk_jobqueue($helper, @args);
    $self->_mk_crontab($helper, @args);
}

sub _mk_jobqueue
{
    my ( $self, $helper, @args ) = @_;

    my $base    = $helper->{base};
    my $app     = $helper->{app};
    my $appprefix = lc($app);
    $appprefix =~ s/::/_/;
    my $filename  = File::Spec->catfile( $base, 'script', "${appprefix}_jobqueue.pl");
    $helper->render_file( 'jobqueue', $filename, { appprefix => $appprefix, scriptgen => $CATALYST_SCRIPT_GEN } );
    chmod 0700, $filename; 
}

sub _mk_crontab
{
    my ( $self, $helper, @args ) = @_;

    my $base = $helper->{base};
    my $filename = File::Spec->catfile( $base, "crontab" );
    $helper->render_file( 'crontab', $filename );
}

return 1;
__DATA__

__jobqueue__
#!/usr/bin/env perl -w

BEGIN {
    $ENV{CATALYST_ENGINE} = 'JobQueue::POE';
    $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %];
}

use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use FindBin;
use lib "$FindBin::Bin/../lib";

$ENV{CATALYST_HOME} = "$FindBin::Bin/..";

my $debug             = 0;
my $fork              = 0;
my $help              = 0;
my $crontab           = "$FindBin::Bin/crontab";

my @argv = @ARGV;

GetOptions(
    'debug|d'       => \$debug,
    'fork'          => \$fork,
    'help|?'        => \$help,
    'crontab|c'     => \$crontab,
);

pod2usage(1) if $help;

if ( $debug ) {
    $ENV{CATALYST_DEBUG} = 1;
    $ENV{CATALYST_POE_DEBUG} = 1;
}

# This is require instead of use so that the above environment
# variables can be set at runtime.

require [% app %];

[% app %]->run( {
    argv        => \@argv,
    'fork'      => $fork,



( run in 1.084 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )