连接redis读取配置文件。

This commit is contained in:
YuleiLan 2020-08-21 10:32:14 +08:00
parent a00816f7a5
commit 8334ba32ec
4 changed files with 18 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"ferry/database"
"ferry/global/orm"
"ferry/pkg/logger"
"ferry/pkg/task"
"ferry/router"
"ferry/tools"
config2 "ferry/tools/config"
@ -56,6 +57,8 @@ func setup() {
config2.ConfigSetup(config)
// 2. 初始化数据库链接
database.Setup()
// 3. 启动异步任务队列
go task.Start()
}

View File

@ -2,12 +2,8 @@ package main
import (
"ferry/cmd"
"ferry/pkg/task"
)
func main() {
// 启动异步任务队列
go task.Start()
cmd.Execute()
}

View File

@ -10,8 +10,11 @@ import (
)
func Start() {
// 启动异步任务框架
taskWorker := worker.NewAsyncTaskWorker(0)
// 1. 启动服务连接redis
worker.StartServer()
// 2. 启动异步调度
taskWorker := worker.NewAsyncTaskWorker(1)
err := taskWorker.Launch()
if err != nil {
logger.Errorf("启动machinery失败%v", err.Error())

View File

@ -2,6 +2,9 @@ package worker
import (
"ferry/pkg/logger"
"fmt"
"github.com/spf13/viper"
"github.com/RichardKnop/machinery/v1"
taskConfig "github.com/RichardKnop/machinery/v1/config"
@ -10,7 +13,7 @@ import (
var AsyncTaskCenter *machinery.Server
func init() {
func StartServer() {
tc, err := NewTaskCenter()
if err != nil {
panic(err)
@ -20,7 +23,10 @@ func init() {
func NewTaskCenter() (*machinery.Server, error) {
cnf := &taskConfig.Config{
Broker: "redis://127.0.0.1:6379",
Broker: fmt.Sprintf("redis://%v:%v",
viper.GetString("settings.redis.host"),
viper.GetString("settings.redis.port"),
),
DefaultQueue: "ServerTasksQueue",
ResultBackend: "eager",
}