Commit 4e7f8080 by huangchengyi

1.0

parent 06339684
......@@ -2,8 +2,11 @@ package main
import (
"flag"
"fmt"
"go_sku_server/boot"
"go_sku_server/pkg/logger"
"go_sku_server/service"
"github.com/jasonlvhit/gocron"
)
//定时任务计算系数价格
......@@ -19,6 +22,22 @@ func main() {
panic(err)
}
logger.Log("启动任务","ratio",1)
ZyCronService := service.ZyCronService{}
ZyCronService.ZyDiscount(goods_id)
//定时任务,每隔3天统计一次
err := gocron.Every(3).Day().At("1:20").Do(ZyDiscount,goods_id)
<- gocron.Start()
fmt.Print("启动任务状态",err)
}
/*
任务执行
*/
func ZyDiscount(goods_id string) {
logger.Log("定时执行任务","ratio",1)
ZyCronService := service.ZyCronService{}
ZyCronService.ZyDiscount(goods_id)
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ require (
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/logger v1.0.5
github.com/imroc/req v0.3.0
github.com/jasonlvhit/gocron v0.0.1 // indirect
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/micro/go-micro v1.16.0
github.com/micro/go-micro/v2 v2.9.0
......
......@@ -4,15 +4,21 @@
一:启动http 对外服务:
cd cmd/http
go build -o ./http ./http_server.go
chmod -R 755 http
chmod +x http
运行-线上: ./http -config=../../conf/prod
运行-开发: ./http -config=../../conf/dev
二:启动定时任务
二:增加定时任务:
cd cmd/cron
go build -o ./cron ./cron_server.go
增加定时crontab 任务:
运行-线上: 0 0 */3 * * cd /go_sku_server/cmd/cron/ && ./cron -config=../../conf/prod
运行-开发: 0 0 */3 * * cd /go_sku_server/cmd/cron/ && ./cron -config=../../conf/dev
chmod -R 755 cron
chmod +x cron
运行-线上: ./cron -config=../../conf/prod
运行-开发: ./cron -config=../../conf/dev
一共两个任务,最好都配置supervisor
### 目录结构
├── bat //运行脚本或者protoc生成脚本
......
......@@ -44,7 +44,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
for goods_id,info := range skuArr {
if gjson.Get(info, "goods_name").String() == "" {
fmt.Print("报错1001-----",goods_id,skuArr)
fmt.Print("报错redis 1001-----",goods_id,skuArr)
}
//拼接梯度价格
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment