App Engine Python UrlFetch.set_default_fetch_deadline [英] App Engine Python UrlFetch.set_default_fetch_deadline

查看:166
本文介绍了App Engine Python UrlFetch.set_default_fetch_deadline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我还发现这个与我的问题有关的堆栈溢出问题:
如何在Google App Engine中为urlfetch设置超时值?



我从我的应用程序引擎应用程序连接到外部Web服务,没有控制权。有时这些请求需要超过60秒。我将应用程序设置为使用延期应用程序引擎任务队列API。



我很困惑。在我看过的文档中,似乎urlfetch的最大截止时间为60秒。但是如果它在task_queue中运行,那么它需要10分钟?我真的只需要有人为我澄清这一点。

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

伪代码:

  myTask = newTask()
deferred.defer(myTask.long_process,_queue =myqueue)

class newTask:
url =https://example.com
def long_process(self):
#将最后期限设置为60秒以上吗?
urlfetch.set_default_fetch_deadline(120)
data = {}
resp = urlfetch.fetch(self.url,method =POST,payload = data)
# resp ....


解决方案

跟踪。微小的更正:urlfetch.set_default_fetch_deadline()最多不超过60s,它可能会被讨论的上下文所误导。

您可以将 120 价值高达 600 ,请参阅OP对最近Q& A中所选答案的评论:之前,Appengine任务运行5秒钟

>

I have looked through the docs here: https://cloud.google.com/appengine/docs/python/urlfetch/ and here: https://cloud.google.com/appengine/articles/deadlineexceedederrors?hl=en

I also found this stack overflow question which relates to my question: How to set timeout for urlfetch in Google App Engine?

I am connecting from my app engine app to an outside web service, that I do not have control over. Sometimes the requests take longer than 60 seconds. I set my application up to use the deferred app engine task queue api.

I am so confused. In the docs I've read it seems as though urlfetch has a maximum deadline of 60 seconds. But if its running in a task_queue it's 10 minutes? I really just need someone to clarify this for me.

Does that mean the task has 10 minutes to complete, but the urlfetch inside the task is still limited to the 60 seconds?

Pseudocode:

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....

解决方案

You're on the right track. Tiny correction: there is no 60s max for urlfetch.set_default_fetch_deadline(), it you might have been misled by the context of the discussion.

You can bump the 120 value up to 600, see the OP's comment to the selected answer in this recent Q&A: Appengine task runs for 5 seconds before throwing DeadlineExceededError

这篇关于App Engine Python UrlFetch.set_default_fetch_deadline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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