postgresql - 如何在多 goroutines 中运行 postgres Tx
问题描述
我必须在 groutine 中运行 tx.exec(),但它总是返回pq: bad conenction
并且pq: unexpected Parse response 'D'
这是我的代码示例:
func (uc OdooUseCase) SynchronizeTourPackage(tourPackageID, partnerID string, odooPackageID int64) (err error) {
var wg sync.WaitGroup
odooUc := OdooUseCase{UcContract: uc.UcContract}
odooDB, err := odooUc.BuildConnection(partnerID)
if err != nil {
logruslogger.Log(logruslogger.WarnLevel, err.Error(), functioncaller.PrintFuncName(), "odoo-build-connection")
return err
}
defer odooDB.Close()
tourPackagePriceUseCase := TourPackagePriceUseCase{UcContract: uc.UcContract, odooDB: odooDB}
tourPackageMealUseCase := TourPackageMealUseCase{UcContract: uc.UcContract, odooDB: odooDB}
errs := make(chan error)
wg.Add(1)
go func() {
wg.Wait()
close(errs)
}()
wg.Add(1)
go func() {
err := tourPackagePriceUseCase.SaveFromOdoo(tourPackageID, partnerID, odooPackageID)
if err != nil {
logruslogger.Log(logruslogger.WarnLevel, err.Error(), functioncaller.PrintFuncName(), "save-tour-package-price", uc.ReqID)
errs <- err
}
defer wg.Done()
}()
wg.Add(1)
go func() {
err := tourPackageMealUseCase.SaveFromOdoo(tourPackageID, partnerID, odooPackageID)
if err != nil {
logruslogger.Log(logruslogger.WarnLevel, err.Error(), functioncaller.PrintFuncName(), "save-tour-package-meal", uc.ReqID)
errs <- err
}
defer wg.Done()
}()
err = <-errs
return err
}
我需要在 go 例程中运行一个 tx.exec,因为这个函数是从另一个数据库同步的。请问有人可以帮助我吗?谢谢
解决方案
推荐阅读
- javascript - 无法访问属性对象 React
- python - 如何计算Dataframe中重复元素的数量并给它一个计数
- javascript - Datalist 返回选项的数据值
- java - 两个数字的所有组合
- javascript - TypeError:无法读取未定义 NodeJS 的属性“名称”
- database - 为烧瓶网络应用程序存储和检索许多小文本文档的最佳方法是什么
- javascript - CORS 标头“Access-Control-Allow-Origin”缺失错误,但它在响应标头中 *is*
- vue.js - 如何在 VueJs 中使用新的 div 推送文本?
- python - 在多种条件下左连接两个熊猫数据框
- node.js - Sequelize - 查询模型和相关模型 - 或