Actually, it doesn't result in async-like behaviour, the client is
still waiting for the function inside the commit hook. I guess I don't
understand the concept then.

On Thu, 10 Jan 2019 at 13:15, Zsolt Ero <[email protected]> wrote:
>
> I'm just now implementing this. Are you saying that basically, by using 
> addAfterCommitHook, I can replace put relatively fast (say, <10 seconds), 
> functions into async-like behaviour, without requiring any external queue 
> service?
>
> old:
>
> # send email was an async function, via a decorator (using Huey)
> send_email(
>     to_email=user.email,
>     subject='account activation',
>     text=email_text,
> )
>
>
>
>
>
> new:
>
> request.tm.get().addAfterCommitHook(send_email_hook, kws=dict(
>     to_email=user.email,
>     subject='account activation',
>     text=email_text,
> ))
>
>
> + a helper function:
>
>
> def send_email_hook(success, **kwargs):
>     if success:
>         send_email(**kwargs)
>
> I have two questions regarding this:
> 1. When does success == False?
> 2. What does the warning on transaction's doc page mean?
>
>> Hook functions which do raise or propagate exceptions will leave the 
>> application in an undefined state.
>
>
> Practically speaking, should I put the send_email function into a try-except 
> block?
>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "pylons-discuss" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/pylons-discuss/tf5kKsnZRTc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pylons-discuss/6831e434-6e85-4c41-9797-82c71ad7f2b3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAKw-smAukCYyjhg7wp2PoP4cUCJ0JuchNqYG0LLHpVGGL%2B84mA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to