2016-06-09 55 views
0

我請求與14MB左右大小從urllib2.urlopen一個緩慢的服務器上的文件,並且它花費超過60秒來獲取數據,而我得到的錯誤:用GAE可以避免urllib2.urlopen中的60秒限制嗎?

Deadline exceeded while waiting for HTTP response from URL: http://bigfile.zip?type=CSV

這裏我的代碼:

class CronChargeBT(webapp2.RequestHandler): 
    def get(self): 
     taskqueue.add(queue_name = 'optimized-queue', url='/cronChargeBTB') 

class CronChargeBTB(webapp2.RequestHandler): 
    def post(self): 
     url = "http://bigfile.zip?type=CSV" 

     url_request = urllib2.Request(url) 
     url_request.add_header('Accept-encoding', 'gzip') 

     urlfetch.set_default_fetch_deadline(300) 
     response = urllib2.urlopen(url_request, timeout=300) 

     buf = StringIO(response.read()) 
     f = gzip.GzipFile(fileobj=buf) 
     ...work with the data insiste the file... 

我創建了一個調用CronChargeBT的cron任務。在這裏,cron.yaml:

- description: cargar BlueTomato 
    url: /cronChargeBT 
    target: charge 
    schedule: every wed,sun 01:00 

,並創建一個新的任務,並插入到隊列中,這裏的隊列配置:

- name: optimized-queue 
    rate: 40/s 
    bucket_size: 60 
    max_concurrent_requests: 10 
    retry_parameters: 
    task_retry_limit: 1 
    min_backoff_seconds: 10 
    max_backoff_seconds: 200 

coursethat超時= 300是行不通的,因爲60秒限制在GAE中,但我認爲我可以避免使用任務...任何人都知道如何在文件中獲取數據,避免超時。

非常感謝!

回答

1

Cron職位限於10分鐘截止日期,而不是60秒。如果你的下載失敗了,也許只是重試?如果您從計算機上下載,下載工作是否正常?如果您從下載的服務器速度太慢或不穩定,那麼您無法在GAE上執行任何操作。

編輯:根據https://cloud.google.com/appengine/docs/java/outbound-requests#request_timeouts,cron作業請求的最大截止時間爲60秒。因此,你無法繞過它。

+0

感謝@kanghj,我認爲我得到的超時錯誤與urllib2.request相關,而不是cron作業。我可以在不到10分鐘,也就是3分鐘的時間內從我的計算機上下載文件,並且代碼在我的開發計算機上工作正常 –

+0

根據https://cloud.google.com/appengine/docs/java/outbound-請求#request_timeouts,cron作業請求的最大截止時間爲60秒。這可能是你的瓶頸。那是你正在觀察的嗎? – kanghj91

+1

有效地,你無法繞過它,因爲它受到GAE本身的限制。 – kanghj91