This commit is contained in:
merdan 2023-05-03 14:56:23 +05:00
parent feb10c15ef
commit 22f275fb03
2 changed files with 9 additions and 7 deletions

View File

@ -140,8 +140,8 @@ func GetWishlistProducts(db *gorm.DB) ([]Product, error) {
func GetFlatSources(db *gorm.DB) ([]ProductAttributeValue, error) { func GetFlatSources(db *gorm.DB) ([]ProductAttributeValue, error) {
var productSources []ProductAttributeValue var productSources []ProductAttributeValue
err := db.Joins("JOIN wishlist wp ON product_attribute_values.product_id = wp.product_id"). err := db.Joins("JOIN wishlist wp ON product_attribute_values.product_id = wp.product_id").
Joins("JOIN marketplace_products mp ON product_attribute_values.product_id = mp.product_id where marketplace_seller_id=1"). Joins("JOIN marketplace_products mp ON product_attribute_values.product_id = mp.product_id").
Find(&productSources, "text_value IS NOT NULL AND attribute_id=31").Error Find(&productSources, "mp.marketplace_seller_id=1 AND product_attribute_values.text_value IS NOT NULL AND product_attribute_values.attribute_id=31").Error
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())

12
main.go
View File

@ -40,7 +40,6 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("Error connecting to database: %s", err) log.Fatalf("Error connecting to database: %s", err)
} }
importer, _ := repositories.ParseImporterInstance(db)
updatePeriodStr := os.Getenv("UPDATE_PERIOD") updatePeriodStr := os.Getenv("UPDATE_PERIOD")
updatePeriod, err := time.ParseDuration(updatePeriodStr) updatePeriod, err := time.ParseDuration(updatePeriodStr)
@ -49,7 +48,7 @@ func main() {
} }
// Start the worker // Start the worker
stopCh := make(chan struct{}) stopCh := make(chan struct{})
go worker(importer, stopCh, updatePeriod) go worker(db, stopCh, updatePeriod)
// Wait for termination signal // Wait for termination signal
signalCh := make(chan os.Signal, 1) signalCh := make(chan os.Signal, 1)
@ -70,10 +69,13 @@ func main() {
} }
} }
func worker(importer *repositories.Importer, stopCh <-chan struct{}, updatePeriod time.Duration) { func worker(db *gorm.DB, stopCh <-chan struct{}, updatePeriod time.Duration) {
ticker := time.NewTicker(updatePeriod) importer, _ := repositories.ParseImporterInstance(db)
ticker := time.NewTicker(time.Second)
ticker = time.NewTicker(updatePeriod)
defer ticker.Stop() defer ticker.Stop()
log.Printf("Updater worker Started") log.Printf("Updater worker Started")
for { for {
select { select {
case <-stopCh: case <-stopCh:
@ -85,7 +87,7 @@ func worker(importer *repositories.Importer, stopCh <-chan struct{}, updatePerio
log.Println("Error retrieving products:", err) log.Println("Error retrieving products:", err)
continue continue
} else { } else {
log.Println(len(result)) log.Println(result)
} }
// Update products as needed // Update products as needed