Hello Thierry, You are talking about these data managers: http://zodb.readthedocs.io/en/latest/transactions.html#data-managers Correct? Other than the Mailer <https://github.com/Pylons/pyramid_mailer> it seems a little difficult to find more verbose documentation?
I have played a little more with the after-commit hook and this short piece of code seems to work: @view_config( … ) def some_view(request): # Do some view stuff, modify db objects, etc. # Local helper function that issues the message to the broker. This # function has access to the closure but beware that db objects are # committed and invalid! def _send_message(success, *args, **kwargs): if success: # Send message to the broker, thus spawning a worker task. dramatiq_actors.some_task.send(*args) # Or Celery tasks, whatever. # Get the transaction for this request. t = request.tm.get() # Arguments for the task. args = ( foo, 3, ) kwargs = {} # Add the after-commit hook, i.e. call _send_message() when the # request's transaction has committed. t.addAfterCommitHook(_send_message, args=args, kws=kwargs) # And return from the view function. return { "some": "results", } It looks to me that this is an acceptable solution if the called hook function can not fail (i.e. return success/failure) and therewith can not contribute to the transaction to fail/succeed. However, a data manager solution makes sense if data must be managed and processing/persisting that data may fail which impacts the overall transaction. Any recommendations here? Cheers, Jens On Friday, June 1, 2018 at 5:06:35 PM UTC+10, Thierry Florac wrote: > > Hi, > Maybe you should have a look at the "DataManager" component interface > provided by the "transaction" package. > This kind of component allows you to include your hook in a "two-phase > commit" transaction safely. > Several implementations are available, for example in the > "repoze.sendmail" package... > > Best regards, > Thierry > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/7f6ccda4-865f-4070-9610-dc5f691ba8e9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.