I use Redis to queue mail for Sendmail and to record usage stats. I
made a 'request.mailer' object with a 'send' method that takes an
email message (bytes with headers) and uses 'pyramid.tm''s two-phase
transaction to append it to a local list, and then in commit to append
it to a Redis list. I had to do that because you can't roll back in
Redis. Then a half-hourly cron job sends the messages.

It was all straightforward except for setting up the two-phased
commit. That required reading the source of 'pyramid_transaction' and
its dependencies to figure out how to attach the mailer to the
transaction. That required adding several methods, several of which
are empty because they're irrelevant.
On Sat, Nov 10, 2018 at 9:28 PM Tim Hoffman <[email protected]> wrote:
>
> Why not publish to a redis qiueue, and then use a separate workers to do the 
> writes.
>
> redis publish is light weight and fast
>
> T
>
> On Sunday, November 11, 2018 at 6:25:36 AM UTC+8, Zsolt Ero wrote:
>>
>> 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/bd6f6169-92dc-47c4-933f-60eb801a1c3a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Mike Orr <[email protected]>

-- 
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/CAH9f%3DuqhxZGDyh%2BPQcsFEN3TvPyJa-gOf5CHgLZ3OKVyM50-jw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to