add background get price job
This commit is contained in:
@@ -7,6 +7,6 @@ var c *cron.Cron
|
||||
// SetCronJob -
|
||||
func SetCronJob() {
|
||||
c = cron.New()
|
||||
|
||||
c.AddFunc("0 0 0,12 * * *", runMTGPriceJob)
|
||||
c.Start()
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user