seller id deadlock and delete elapsed time

This commit is contained in:
merdan 2022-09-21 11:42:19 +05:00
parent 95f7d46beb
commit e5015c2c66
1 changed files with 17 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import (
"os"
"strconv"
"sync"
"sync/atomic"
"time"
"gorm.io/driver/mysql"
@ -26,9 +27,25 @@ var (
families []gm.AttributeFamily
sellers = make(map[string]gm.MarketplaceSeller)
AttributesMap = make(map[string]gm.Attribute)
locker = stateUnlocked
)
const (
stateUnlocked uint32 = iota
stateLocked
)
func StartImport(w http.ResponseWriter, route *http.Request) {
// lock the request
if !atomic.CompareAndSwapUint32(&locker, stateUnlocked, stateLocked) {
w.WriteHeader(http.StatusTooManyRequests)
json.NewEncoder(w).Encode(map[string]string{
"msg": "Scraper or Updater in progress!",
})
return
}
defer atomic.StoreUint32(&locker, stateUnlocked)
start := time.Now()
r := new(big.Int)