On Fri, Apr 13, 2007 at 02:28:59PM -0400, Perrin Harkins wrote:
> On 4/13/07, Bill Moseley <[EMAIL PROTECTED]> wrote:
> > So, for example, in Catalyst in an end() (or something at the end) you
> > would look for errors and then do a rollback, otherwise commit?  And
> > you look at AutoCommit to see if you need to do either of those, I
> > assume.
> 
> No, it's much simpler than that.  Maybe Catalyst complicates things
> with some extra eval wrapping.  In my CGI::Application app, I just
> turn on RaiseError.  If nothing goes wrong, the changes get committed
> when I exit the block with AutoCommit turned off.  There's no need for
> an explicit commit.  (And because I use local $sbh->{AutoCommit}, it
> won't commit until I leave the highest level block that initiated a
> transaction, so it amounts to fake nested transactions but with
> automatic scoping.)

Catalyst does wrap the requests in eval, so if a controller dies you
have to look for the exception stuffed int $c->errors somewhere 

If you don't mind doing a rollback on all requests then that sure
makes things nice and simple.  Thanks.

> My transactions are as small as possible, to avoid holding locks.  I
> only use longer ones in bulk loading situations where it makes a big
> difference.  I'm not really following why the fake nested transactions
> help with this.
> 
> > Perhaps a cleaner way (other than queuing up the task for an external
> > process) would be push a sub onto an array with the code to run after 
> > calling
> > commit.
> 
> Sorry, I'm not sure what problem you're trying to solve there.

To avoid running code that you only want to happen if the transaction
commits.  For example, sending an email.

If you have one sub:

    do_stuff_and_send_mail {

        {
            local $dbh->{AutoCommit} = 0;
            $object->do_stuff;
        } # commit (unless nested)

        send_mail( "do_stuff happened!" );
    }

Obviously, the mail won't be sent if there's an exception.  But, if
do_stuff_and_sent_mail() is called from code that's in a transaction
(nested transaction) then send_mail can happen, and after the sub
above returns an exception would roll back the entire transaction.
But send_mail() still already sent the mail.

So, I was saying:

    push @{ $c->stash->{end_tasks} }, sub { send_mail( "happened" ) };

Then in Cat's end() action run those sub unless an exception happened.

-- 
Bill Moseley
[EMAIL PROTECTED]


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to