@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
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
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
--
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-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
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 pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
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.
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 pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/c44e1af6-8c30-478e-9baf-d7fd8c93e0b5%40googlegroups.com.
Please not that thread local `transaction.manager` might be discouraged nowadays, but not sure what is the best practice to get a transaction manager for your request.
# send email was an async function, via a decorator (using Huey)
send_email(
to_email=user.email,
subject='account activation',
text=email_text,
)
request.tm.get().addAfterCommitHook(send_email_hook, kws=dict(
to_email=user.email,
subject='account activation',
text=email_text,
))
+ a helper function:
def send_email_hook(success, **kwargs):
if success:
send_email(**kwargs)
Hook functions which do raise or propagate exceptions will leave the application in an undefined state.
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-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAKw-smAukCYyjhg7wp2PoP4cUCJ0JuchNqYG0LLHpVGGL%2B84mA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAKw-smCPd0j-sCuHzMa0b-sXNdXrRzB%2BWs2JHzsx5Tu6w02c7A%40mail.gmail.com.
So I guess the simplest possible solution is Celery + Redis (since I'm already using Redis for sessions), I guess?
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAKw-smCPd0j-sCuHzMa0b-sXNdXrRzB%2BWs2JHzsx5Tu6w02c7A%40mail.gmail.com.