<div dir="ltr">AFAIK there is no native way to make this situation easier, if thats what you are hoping for.  You could make a stack on the engine object where you could pop on things todo when a transaction is committed, and then modify the commit sub to unpop and run the stack after commit.  Not sure how good of a design that is, and makes a lot of action-at-a-distance, making things a bit harder to debug and possibly introducing weird edge case issues.<div><br></div><div>Aran</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 23, 2014 at 1:32 AM, Dami Laurent (PJ) <span dir="ltr">&lt;<a href="mailto:laurent.dami@justice.ge.ch" target="_blank">laurent.dami@justice.ge.ch</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi there,<br>
<br>
I encountered a delicate situation involving nested transactions.<br>
Consider a subroutine more or less like this :<br>
<br>
  sub insert_and_publish {<br>
    my @keys = $schema-&gt;txn_do(sub {some_complex_inserts()});<br>
    publish_to_outer_world(@keys);<br>
  }<br>
<br>
This creates a bunch of records within a transaction. If the transaction succeeds, changes are commited to the database, and then we can publish the record keys to other processes. With one single transaction, everything is well. However, if this is called from another transaction, we get into trouble :<br>
<br>
  $schema-&gt;txn_do(sub {<br>
    insert_and_publish();<br>
    do_some_more_stuff();<br>
   });<br>
   # only now did the real commit take place<br>
<br>
The problem here is that because of nested transactions, the commit only takes place at the outermost level; so the sequence of operations in insert_and_publish() no longer works : other processes get notified about keys that have not been committed yet (because do_some_more_stuf() might take some time), or possibly will never be committed (because do_some_more_stuf() might fail).<br>
<br>
The question is : how to rewrite insert_and_publish() so that it would work equally well in a single transaction, or in a nested transaction ? It seems that what is needed is a callback mechanism, to record things that should be done just after the transaction, and would be called automatically after commit time. Any suggestions ?<br>
<br>
Thanks in advance, Laurent Dami<br>
<br>
_______________________________________________<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a><br>
IRC: <a href="http://irc.perl.org#dbix-class" target="_blank">irc.perl.org#dbix-class</a><br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a><br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" target="_blank">http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</a><br>
</blockquote></div><br></div>