Hi Jens, You can also look here for inspiration:
https://websauna.org/docs/narrative/misc/task.html#delayed-tasks On 1 June 2018 at 05:34, <[email protected]> wrote: > Hi, > > Within a view function it becomes necessary to run an async task. Celery > <http://www.celeryproject.org/>, Dramatiq <https://dramatiq.io/>, etc are > frameworks to handle that. However, my async task needs to read db objects > which have been created—and must be committed and persisted—by the view > function that spawns the task. Thus, I need to delay spawning the task > (i.e. sending the task’s message to the workers) until after the request’s > db transaction has committed. > > The db transaction is a standard SQLAlchemy transaction. Using the commit > veto hook > <https://docs.pylonsproject.org/projects/pyramid_tm/en/latest/#adding-a-commit-veto-hook> > is too early. This SO answer > <https://stackoverflow.com/questions/17499171/pyramid-zopetransactionextension-with-celery-how-can-i-commit-transaction-immed#17507093> > suggests using the repoze.tm.after_end() > <http://repozetm2.readthedocs.io/en/latest/#cleanup> callback, but the > answer is about five years old now. > > How do I handle this scenario correctly, i.e. how do I schedule an async > job after a request was successful? I guess I can pack up the task object, > or a signature, and its parameters and attach them to the request from > within the view function. But where is the right place to actually send the > task message? > > Thanks! > Jens > > > -- > 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/ef6bf67d-acec-4dae-b318-7749743add31% > 40googlegroups.com > <https://groups.google.com/d/msgid/pylons-discuss/ef6bf67d-acec-4dae-b318-7749743add31%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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/CAK8RCUvcOO0pYd%2Br_r20FfSsT6p_1edw7AfPrRXTqf5Z8dQUVw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
