add background get price job

This commit is contained in:
Jay
2019-01-18 16:39:02 +08:00
parent efaf0c2fdd
commit ca453dd773
6 changed files with 58 additions and 12 deletions
+1 -1
View File
@@ -7,6 +7,6 @@ var c *cron.Cron
// SetCronJob -
func SetCronJob() {
c = cron.New()
c.AddFunc("0 0 0,12 * * *", runMTGPriceJob)
c.Start()
}
+15 -1
View File
@@ -1,12 +1,20 @@
package background
import (
"log"
"time"
"git.trj.tw/golang/mtgbot/models"
"git.trj.tw/golang/mtgbot/modules/apiact"
"git.trj.tw/golang/mtgbot/modules/pool"
"git.trj.tw/golang/utils"
)
func RunMTG() {
log.Println("run :::::::: ")
runMTGPriceJob()
}
func runMTGPriceJob() {
api, err := apiact.NewTCGApi("v1.19.0")
if err != nil {
@@ -33,6 +41,9 @@ func runMTGPriceJob() {
pool := pool.NewPool(5)
for _, set := range sets {
if set.TCGPlayerID <= 0 {
continue
}
pool.Add()
go getPriceFromAPI(pool, api, set.TCGPlayerID)
}
@@ -41,7 +52,10 @@ func runMTGPriceJob() {
}
func getPriceFromAPI(pool *pool.Pool, api *apiact.TCGPlayer, groupid int) {
defer pool.Done()
defer func() {
time.Sleep(time.Millisecond * 200)
pool.Done()
}()
prices, err := api.ListGroupProductPrice(groupid)
if err != nil {