Re: [pylons-discuss] How to send task-message after request.tm has committed?

2018-06-01 Thread Mikko Ohtamaa
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,  wrote:

> Hi,
>
> Within a view function it becomes necessary to run an async task. Celery
> , Dramatiq , 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
> 
> is too early. This SO answer
> 
> suggests using the repoze.tm.after_end()
>  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 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/ef6bf67d-acec-4dae-b318-7749743add31%
> 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 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/CAK8RCUvcOO0pYd%2Br_r20FfSsT6p_1edw7AfPrRXTqf5Z8dQUVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[pylons-discuss] How to send task-message after request.tm has committed?

2018-05-31 Thread jens . troeger
Hi,

Within a view function it becomes necessary to run an async task. Celery 
, Dramatiq , 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 

 
is too early. This SO answer 

 
suggests using the repoze.tm.after_end() 
 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 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/ef6bf67d-acec-4dae-b318-7749743add31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.