gpt4 book ai didi

google-app-engine - Go Bigquery 上的 DEADLINE_EXCEEDED

转载 作者:IT王子 更新时间:2023-10-29 02:12:06 27 4
gpt4 key购买 nike

我们的应用程序在访问 Big Query 时有时会看到 DEADLINE_EXCEEDED。

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 中更改超时?

最佳答案

在创建 bigquery 客户端的新实例时也使用 ctx_with_deadline:

client, err := bigquery.NewClient(ctx_with_deadline, PROJECT_ID, option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH‌​), option.WithHTTPClient(httpClient))

关于google-app-engine - Go Bigquery 上的 DEADLINE_EXCEEDED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43339181/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com