1 回答
TA贡献1789条经验 获得超8个赞
如错误所述,您无法同时添加策略。我建议您并行生成创建请求并序列化实际的 API 调用。您可以通过缓冲通道和多个 go 例程来实现此目的。例如:
var(
backlogSize = 3 //change as per your needs
requests = make(chan *monitoring.AlertPolicy, backlogSize)
)
func createPolicies(){
...
go func(){
//init the service
...
for policy := range requests {
p, err := service.Projects.AlertPolicies.Create("projects/abc-app", policy).Context(context.Background()).Do()
if err != nil {
log.Println(err)
}
}
}()
go func(){
newPolicy := &monitoring.AlertPolicy
//fill policy
...
requests <- newPolicy
}()
...
//wait for completion and close requests channel
}
另一种解决方案是使用指数退避+抖动重试每个失败的并发请求
- 1 回答
- 0 关注
- 128 浏览
添加回答
举报