I have several use cases where a request generates long operations (for
example, for doing conversion of an uploaded video file) but I want that
the end user receives the response as soon as possible (here, before
conversion ends).
In these cases, if the long operation is not impacted by the status of my
current transaction, and as I don't want to be dependent of a client-side
call, my choice was to:
- start a 0MQ listening process on application startup
- when a given request is received, just start a new thread to send the
required arguments to the listening 0MQ process, and send response
immediately! If this step is just dependent of current transaction status,
just be use to use an after-commit hook or a transaction data-manager...

Thierry

Le sam. 10 nov. 2018 à 23:25, Zsolt Ero <[email protected]> a écrit :

> On a fairly classic Pyramid app (sync, gunicorn, SQLAlchemy / Postgresql,
> like the starter template), I am storing analytics-like events in a table
> for some of my views.
>
> Like this skeleton:
>
> @view_config(route_name='test', request_method='POST', renderer='json')
> def test(request):
>     # body of the view
>     map_id = request.json_body.get('map_id')
>     data = {...}
>
>     event_data = {'action': 'viewed'}
>     event = MapEvent(user=request.user, action=event_data, map_id=map_id)
>     request.dbsession.add(event)
>
>     return data
>
>
>
> My problem is that while 99% of the views make read-only requests to the
> database, and thus are very fast, the analytics event is a writing and can
> be slow occasionally.
>
> Would it be possible to somehow send the request to the client and still
> keep processing the view? Like a send() + end() method or something
> similar, without returning?
>
> // Adding to a tasks queue is not an option as it'd be an overkill and an
> overcomplicated solution, which wouldn't work for hundreds of thousands of
> events per day.
>
>
> --
> 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/c44e1af6-8c30-478e-9baf-d7fd8c93e0b5%40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/c44e1af6-8c30-478e-9baf-d7fd8c93e0b5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
http://www.imagesdusport.com -- http://pyams.readthedocs.io

-- 
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/CAPX_VWAeAHv_MHFHN0VM5WAXJ7XarUm5eAfaDJhEk71BqyNT%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to