Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MyApp::TheSchwartz::Client;
- use TheSchwartz;
- sub theschwartz {
- my $theschwartz = TheSchwartz->new(
- databases => [ {
- dsn => 'dbi:mysql:theschwartz',
- user => 'user',
- pass => 'pass',
- } ],
- verbose => 1,
- );
- return $theschwartz;
- }
- package MyApp::TheSchwartz::Worker::Test;
- use base qw( TheSchwartz::Moosified::Worker );
- use MyApp::Model::DB; # Catalyst DB connect_info
- use MyApp::Schema; # Catalyst DB schema
- sub work {
- my $class = shift;
- my $job = shift;
- my ($args) = $job->arg;
- my ($arg1, $arg2) = @$args;
- # re-use Catalyst DB schema
- my $connect_info = MyApp::Model::DB->config->{connect_info};
- my $schema = MyApp::Schema->connect($connect_info);
- # do the heavy lifting
- $job->completed();
- }
- use MyApp::TheSchwartz::Client qw/theschwartz/; # db connection
- use MyApp::TheSchwartz::Worker::Test;
- use Parallel::Prefork;
- my $client = theschwartz();
- my $pm = Parallel::Prefork->new({
- max_workers => 16,
- trap_signals => {
- TERM => 'TERM',
- HUP => 'TERM',
- USR1 => undef,
- }
- });
- while ($pm->signal_received ne 'TERM') {
- $pm->start and next;
- $client->can_do('MyApp::TheSchwartz::Worker::Test');
- my $delay = 10; # When no job is available, the working process will sleep for $delay seconds
- $client->work( $delay );
- $pm->finish;
- }
- $pm->wait_all_children();
- use MyApp::TheSchwartz::Client qw/theschwartz/;
- $client = theschwartz();
- $client->insert(‘MyApp::TheSchwartz::Worker::Test’, [ $arg1, $arg2 ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement