finish v3
This commit is contained in:
parent
6a15c0ff69
commit
1ce9a63b68
|
|
@ -1,6 +1,7 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
gm "db_service/gorm_models"
|
||||
"db_service/repositories"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
|
@ -39,11 +40,21 @@ func StartProductImport(w http.ResponseWriter, _ *http.Request) {
|
|||
|
||||
if err = importRepo.Start().Error; err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("end import took %s", elapsed)
|
||||
return
|
||||
}
|
||||
|
||||
importRepo.ImportWGroup.Wait()
|
||||
|
||||
//scout index flush
|
||||
if err = gm.Flush(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("end import took %s", elapsed)
|
||||
return
|
||||
}
|
||||
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("end import took %s", elapsed)
|
||||
http.Error(w, fmt.Sprintf("end import took %s", elapsed), http.StatusOK)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Importer struct {
|
||||
|
|
@ -121,6 +122,16 @@ func ImporterInstance() (instance *Importer, err error) {
|
|||
}
|
||||
|
||||
func (importer *Importer) Start() (instance *Importer) {
|
||||
|
||||
log.Println("Start Product delete")
|
||||
deleteTime := time.Now()
|
||||
importer.Error = gm.DeleteProducts(importer.baza)
|
||||
deleteElapsed := time.Since(deleteTime)
|
||||
log.Printf("Delete products took %s", deleteElapsed)
|
||||
|
||||
if importer.Error != nil {
|
||||
return importer
|
||||
}
|
||||
//init wait group to main categories length
|
||||
importer.ImportWGroup.Add(len(importer.mainCategories))
|
||||
//start gorutines for each main category
|
||||
|
|
|
|||
Loading…
Reference in New Issue