Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4e7f8080
authored
Oct 14, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
06339684
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
5 deletions
cmd/cron/cron_server.go
go.mod
readme.md
service/service_zy.go
cmd/cron/cron_server.go
View file @
4e7f8080
...
...
@@ -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
go.mod
View file @
4e7f8080
...
...
@@ -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
...
...
readme.md
View file @
4e7f8080
...
...
@@ -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生成脚本
...
...
service/service_zy.go
View file @
4e7f8080
...
...
@@ -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
)
}
//拼接梯度价格
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment