From dc42eda2fe637fc1353c8b0ed76131f28c8ce17d Mon Sep 17 00:00:00 2001 From: merdan Date: Tue, 6 Sep 2022 16:39:29 +0500 Subject: [PATCH] timout fx --- gorm_models/product.go | 8 +++++--- pkg/request.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gorm_models/product.go b/gorm_models/product.go index 426b2eb..af4ec1b 100644 --- a/gorm_models/product.go +++ b/gorm_models/product.go @@ -1,6 +1,7 @@ package gorm_models import ( + "context" helper "db_service/pkg" "gorm.io/gorm" "os" @@ -94,9 +95,10 @@ func (ProductFlat) TableName() string { func DeleteProducts(db *gorm.DB) error { //todo delete from elastico - - return db.Exec("DELETE p.* FROM products p, order_items oi WHERE p.id NOT IN (select product_id from wishlist) AND p.id NOT IN (select product_id from order_items) AND p.id NOT IN (select parent_id from order_items)").Error - + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + defer cancel() + qb := "DELETE p.* FROM products p, order_items oi WHERE p.id NOT IN (select product_id from wishlist) AND p.id NOT IN (select product_id from order_items) AND p.id NOT IN (select parent_id from order_items)" + return db.WithContext(ctx).Exec(qb).Error } func Flush() error { diff --git a/pkg/request.go b/pkg/request.go index 269b4a1..871e7b2 100644 --- a/pkg/request.go +++ b/pkg/request.go @@ -14,7 +14,7 @@ import ( func SendRequest(method string, endpoint string, values []byte, authKey string, isCouchDbReq bool) ([]byte, error) { const ConnectMaxWaitTime = 30 * time.Second - const RequestMaxWaitTime = 60 * time.Second + const RequestMaxWaitTime = 10 * time.Minute client := http.Client{ Transport: &http.Transport{