Skip to content

Commit

Permalink
test: timezone test
Browse files Browse the repository at this point in the history
  • Loading branch information
slowhigh committed Jun 4, 2024
1 parent 23cc2b2 commit 0103231
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package main
import (
"bytes"
"fmt"
"log"
"log/slog"
"net/smtp"
"os"
"path"
"runtime"
"strconv"
Expand All @@ -15,40 +17,42 @@ import (
"github.com/jasonlvhit/gocron"
"github.com/spf13/viper"
"github.com/team-nerd-planet/send-server/entity"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)

func main() {
// conf, err := NewConfig()
// if err != nil {
// panic(err)
// }

// dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable TimeZone=Asia/Seoul",
// conf.Database.Host,
// conf.Database.Port,
// conf.Database.UserName,
// conf.Database.Password,
// conf.Database.DbName,
// )

// newLogger := logger.New(
// log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
// logger.Config{
// SlowThreshold: time.Second, // Slow SQL threshold
// LogLevel: logger.LogLevel(4), // Log level
// IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
// ParameterizedQueries: false, // Don't include params in the SQL log
// Colorful: false, // Disable color
// },
// )

// db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
// Logger: newLogger,
// })
// if err != nil {
// panic(err)
// }
conf, err := NewConfig()
if err != nil {
panic(err)
}

dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable TimeZone=Asia/Seoul",
conf.Database.Host,
conf.Database.Port,
conf.Database.UserName,
conf.Database.Password,
conf.Database.DbName,
)

newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // Slow SQL threshold
LogLevel: logger.LogLevel(4), // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
ParameterizedQueries: false, // Don't include params in the SQL log
Colorful: false, // Disable color
},
)

db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: newLogger,
})
if err != nil {
panic(err)
}

location, err := time.LoadLocation("Asia/Seoul")
if err != nil {
Expand All @@ -60,18 +64,18 @@ func main() {

slog.Info("current time", "time", time.Now())

gocron.Every(1).Day().At("10:12").Do(func() {
gocron.Every(1).Day().At("10:14").Do(func() {
slog.Info("start cron", "time", *location)

// var subscriptionArr []entity.Subscription
var subscriptionArr []entity.Subscription

// if err := db.Find(&subscriptionArr).Error; err != nil {
// panic(err)
// }
if err := db.Find(&subscriptionArr).Error; err != nil {
panic(err)
}

// for _, subscription := range subscriptionArr {
// publish(conf, db, subscription)
// }
for _, subscription := range subscriptionArr {
publish(conf, db, subscription)
}
})

<-gocron.Start()
Expand Down

0 comments on commit 0103231

Please sign in to comment.