I don’t know if there is such a solution inside of the Pyramid scope. Either way, I wouldn’t do it, because it would
Mix business relevant logic with non- business relevant logic in one responsibility level. The latter must not have the ability to influence the first, which is not possible to establish if they are operating on the same level. It would be difficult to manage DB transactions independently if you are operating in one request scope. As you say, you’re not willing to put additional infrastructure complexity on that (which sounds fair to me for the given problem), I would look for a solution outside of your service. Personally I would emit HTTP response headers, which contain your events information. Those can be processed in Nginx, e.g. simply logged in json format, to a separate logfile (which is your events log then). Once you are there, you are free to decide in which cycle, with which tools to continue. Andi From: <[email protected]> on behalf of Zsolt Ero <[email protected]> Reply-To: <[email protected]> Date: Saturday, 10. November 2018 at 23:25 To: pylons-discuss <[email protected]> Subject: [pylons-discuss] processing after responding to client 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. 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/8411C5DA-778C-46AF-A1CE-D7CD403909DB%40googlemail.com. For more options, visit https://groups.google.com/d/optout.
