add timed
This commit is contained in:
@@ -11,10 +11,10 @@ import (
|
||||
|
||||
"tyapi-server/internal/config"
|
||||
"tyapi-server/internal/domains/article/entities"
|
||||
"tyapi-server/internal/infrastructure/database"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -37,28 +37,28 @@ func main() {
|
||||
defer logger.Sync()
|
||||
|
||||
// 连接数据库
|
||||
// 在 Docker 环境中使用容器名
|
||||
dbHost := os.Getenv("DB_HOST")
|
||||
if dbHost == "" {
|
||||
dbHost = cfg.Database.Host
|
||||
// 使用配置文件中的数据库配置
|
||||
dbCfg := database.Config{
|
||||
Host: cfg.Database.Host,
|
||||
Port: cfg.Database.Port,
|
||||
User: cfg.Database.User,
|
||||
Password: cfg.Database.Password,
|
||||
Name: cfg.Database.Name,
|
||||
SSLMode: cfg.Database.SSLMode,
|
||||
Timezone: cfg.Database.Timezone,
|
||||
MaxOpenConns: cfg.Database.MaxOpenConns,
|
||||
MaxIdleConns: cfg.Database.MaxIdleConns,
|
||||
ConnMaxLifetime: cfg.Database.ConnMaxLifetime,
|
||||
}
|
||||
|
||||
// 使用默认端口 5432
|
||||
dbPort := 5432
|
||||
|
||||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
|
||||
dbHost, cfg.Database.User, cfg.Database.Password, cfg.Database.Name, dbPort)
|
||||
fmt.Printf("dsn: %s\n", dsn)
|
||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
logger.Info("数据库配置", zap.Any("dbCfg", dbCfg))
|
||||
dbWrapper, err := database.NewConnection(dbCfg)
|
||||
if err != nil {
|
||||
logger.Fatal("连接数据库失败", zap.Error(err))
|
||||
}
|
||||
db := dbWrapper.DB
|
||||
|
||||
// 从环境变量获取 Redis 地址
|
||||
redisAddr := os.Getenv("REDIS_ADDR")
|
||||
if redisAddr == "" {
|
||||
redisAddr = fmt.Sprintf("%s:%d", cfg.Redis.Host, cfg.Redis.Port)
|
||||
}
|
||||
// 使用配置文件中的Redis配置
|
||||
redisAddr := fmt.Sprintf("%s:%s", cfg.Redis.Host, cfg.Redis.Port)
|
||||
|
||||
// 创建 Asynq Server
|
||||
server := asynq.NewServer(
|
||||
|
||||
Reference in New Issue
Block a user