记录响应后响应的请求 [英] Log that a request was responded to after responding

查看:163
本文介绍了记录响应后响应的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常noobish的问题,但我想确保我的代码正在做我认为它在做的。

This probably is a very noobish question, but I want to make sure my code is doing what I think it's doing.

这是我以后 - 得到一个请求,作出决定,并通过决定回应该请求,然后才能登录。该序列很重要,因为写入速度可能很慢,我想确保在发生任何写入之前发布响应。

Here's what I'm after - get a request, make a decision, respond to it the request with the decision, and only then log it. The sequence is important because writes can be slow and I want to make sure that a response is published before any writes take place.

以下是示例代码:

class ConferenceGreetingHandler(webapp.RequestHandler):
def get(self):
    self.post()

def post(self):

    xml_template(self, 'templates/confgreeting.xml')

    new_log = Log()
    new_log.log = 'test'
    new_log.put()

我想我在服务在采伐前的回应,这其实是真的吗?另外还有更好的方法吗?再次,对于超级无辜的... ...

I think I'm serving a response before logging, is this in fact true? Also, is there a better way to do this? Again, sorry for super-noobishness...

编辑:这是模板:

def xml_template(handler, page, values=None):
    path = os.path.join(os.path.dirname(__file__), page)
    handler.response.headers["Content-Type"] = "text/xml"
    handler.response.out.write(template.render(path, values))


推荐答案

无论你做了什么,App Engine将不会在你的处理程序代码完成之前向用户发送回复。目前没有办法告诉App Engine现在发送回复,我不会再输出。

No matter what you do, App Engine will not send a response to a user until your handler code completes. There's currently no way, unfortunately, to tell App Engine "send the response now, I won't output any more".

你有几个选择:


  1. 只需同步输入日志条目即可。数据存储写入对于延迟时钟延迟并不是非常昂贵的,特别是如果您最小化所需的索引更新次数。

  2. 将任务队列任务写入日志数据。如果您使用拉取队列,则可以从另一个任务或后端分批获取日志条目并将其分批写入数据存储。

  3. 只要您拥有日志条目,就可以立即启动日志条目的数据存储区写入相关数据,并使用异步操作,允许您将写入与您的一些处理重叠。

这篇关于记录响应后响应的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆