Hi everyone,

Been a long time since I've posted on this list, but been using DBIx::Class
for a couple years now and love it... great software.

Anywho, I've wrriten this code which do parallel processing (using
Parallel::Forker) within a single DBIx::Class transaction.  Something is not
working as it throws lock wait timeout errors.  I want to know, is it
possible to use for fork() in general within a single DBIx::Class
transaction?  Each of my child processes is working on different data in the
database, but I want to rollback everything if something fails in any child.

thanks for any insight,
leandro


use My::Schema;

eval {
    my $schema = My::Schema->connect(...);
    $schema->txn_do(sub {

        ... do some database stuff here before forking...

        my $forker = Parallel::Forker->new(use_sig_child => 1, max_proc =>
$num_procs);
        $SIG{CHLD} = sub { Parallel::Forker::sig_child($forker); };
        $SIG{TERM} = sub { $forker->kill_tree_all('TERM') if $forker &&
$forker->in_parent; };
        my @studies = $schema->resultset('Study')->all();
        for my $study (@studies) {
            $forker->schedule(run_on_start => sub {

                ... here in child process code do some heavy processing and
                    then database inserts, deletes using $schema...

            })->ready();
        }
        # wait for all remaining child processes to finish
        $forker->wait_all();
    });
};
if ($@) {
    my $message = "Database transaction failed";
    $message .= " and ROLLBACK FAILED" if $@ =~ /rollback failed/i;
    die "\n\n$message: $...@\n\n";
}
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to