应用引擎 Python UrlFetch.set_default_fetch_deadline

App Engine Python UrlFetch.set_default_fetch_deadline

我在这里查看了文档: https://cloud.google.com/appengine/docs/python/urlfetch/ 和这里: https://cloud.google.com/appengine/articles/deadlineexceedederrors?hl=en

我还发现了与我的问题相关的堆栈溢出问题: How to set timeout for urlfetch in Google App Engine?

我正在从我的 App Engine 应用程序连接到我无法控制的外部 Web 服务。有时请求需要超过 60 秒的时间。我将我的应用程序设置为使用延迟的应用程序引擎任务队列 api。

我很困惑。在我读过的文档中,urlfetch 的最长期限似乎为 60 秒。但是如果它的 运行 在 task_queue 中是 10 分钟?我真的只需要有人为我澄清这一点。

这是否意味着任务有 10 分钟完成,但任务中的 urlfetch 仍然限制在 60 秒内?

伪代码:

myTask = newTask()
deffered.defer(myTask.long_process, _queue="myqueue")

class newTask:
    url = "https://example.com"
def long_process(self):
    #will setting the deadline to more than 60 seconds work or not? 
    urlfetch.set_default_fetch_deadline(120)
    data = {}
    resp = urlfetch.fetch(self.url, method="POST", payload=data)
    #do something with resp....

你走在正确的轨道上。小更正:urlfetch.set_default_fetch_deadline() 没有 60 秒的最大值,你可能被讨论的上下文误导了。

您可以将 120 值提高到 600,请参阅 OP 在最近的问答中对所选答案的评论:

您可以同时控制 urlfetch 和延迟任务截止日期。

两者都可以 运行 最多 600 秒 AFAIK。

您不应该做的一件事是将 urfetch 截止日期设置为比任务更高的值;)