1
我們的應用程序在訪問Big Query時有時會看到DEADLINE_EXCEEDED。DEAST_EXCEEDED在Go Bigquery
import (
"cloud.google.com/go/bigquery"
"golang.org/x/net/context"
"google.golang.org/api/option"
)
func MyFunc(ctx context.Context) {
:
client, err := bigquery.NewClient(ctx, PROJECT_ID, option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH))
query := client.Query("SELECT * FROM ....")
it, err := query.Read(ctx)
var list []MyStruct
for {
var m MyStruct
err := it.Next(&m)
if err == iterator.Done {
break
}
if err != nil {
<Error Handling>
}
list = append(list, m)
}
:
}
有時我們會看到這個錯誤。
Get https://www.googleapis.com/bigquery/v2/projects/myproject/queries/job_zandIeLwH0s8f3FAQ_ORC0zau14?alt=json\u0026startIndex=0\u0026timeoutMs=60000: API error 5 (urlfetch: DEADLINE_EXCEEDED): ('The read operation timed out',)"
它看起來超時是5秒,但我可以'找到如何更改超時秒數。我寫了this post,我修改了我的源代碼如下。
ctx_with_deadline, _ := context.WithTimeout(ctx, 1*time.Minute)
httpClient := &http.Client{
Transport: &oauth2.Transport{
Base: &urlfetch.Transport{Context: ctx_with_deadline},
},
}
client, err := bigquery.NewClient(ctx, PROJECT_ID, option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH), option.WithHTTPClient(httpClient))
然後我遇到了這個錯誤。
Post https://www.googleapis.com/bigquery/v2/projects/myproject/jobs?alt=json: oauth2: Transport's Source is nil
如何在Go Bigquery中更改超時?
你不應該用'ctx_with_deadline'也爲bigquery.NewClient? –
@AlexEfimov它看起來封裝選項沒有截止期限選項。 –
我的意思是像'client,err:= bigquery.NewClient(ctx_with_deadline,PROJECT_ID,option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH),option.WithHTTPClient(httpClient))' –