Skip to content

Commit

Permalink
perf: optimize communication exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DokiDoki1103 committed Jan 10, 2024
1 parent 15f126c commit e28a038
Show file tree
Hide file tree
Showing 22 changed files with 256 additions and 433 deletions.
22 changes: 0 additions & 22 deletions api/db/database.go

This file was deleted.

48 changes: 21 additions & 27 deletions api/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
package db

import (
"encoding/json"
"context"
"github.com/goodrain/rainbond/config/configs"
"time"

tsdbClient "github.com/bluebreezecf/opentsdb-goclient/client"
tsdbConfig "github.com/bluebreezecf/opentsdb-goclient/config"
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/db/config"
dbModel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/mq/api/grpc/pb"
"github.com/goodrain/rainbond/worker/discover/model"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
Expand All @@ -40,13 +39,18 @@ type ConDB struct {
DBType string
}

// CreateDBManager get db manager
// TODO: need to try when happened error, try 4 times
func CreateDBManager(conf option.Config) error {
// Database -
func Database() *ConDB {
return &ConDB{}
}

// Start -
func (d *ConDB) Start(ctx context.Context, cfg *configs.Config) error {
logrus.Info("start db client...")
dbCfg := config.Config{
MysqlConnectionInfo: conf.DBConnectionInfo,
DBType: conf.DBType,
ShowSQL: conf.ShowSQL,
MysqlConnectionInfo: cfg.APIConfig.DBConnectionInfo,
DBType: cfg.APIConfig.DBType,
ShowSQL: cfg.APIConfig.ShowSQL,
}
if err := db.CreateManager(dbCfg); err != nil {
logrus.Errorf("get db manager failed,%s", err.Error())
Expand All @@ -58,6 +62,14 @@ func CreateDBManager(conf option.Config) error {
return nil
}

// CloseHandle -
func (d *ConDB) CloseHandle() {
err := db.CloseManager()
if err != nil {
logrus.Errorf("close db manager failed,%s", err.Error())
}
}

// TaskStruct task struct
type TaskStruct struct {
TaskType string
Expand All @@ -82,24 +94,6 @@ func (o *OpentsdbManager) NewOpentsdbManager() (tsdbClient.Client, error) {
return tc, nil
}

// BuildTask build task
func BuildTask(t *TaskStruct) (*pb.EnqueueRequest, error) {
var er pb.EnqueueRequest
taskJSON, err := json.Marshal(t.TaskBody)
if err != nil {
logrus.Errorf("tran task json error")
return &er, err
}
er.Topic = "worker"
er.Message = &pb.TaskMessage{
TaskType: t.TaskType,
CreateTime: time.Now().Format(time.RFC3339),
TaskBody: taskJSON,
User: t.User,
}
return &er, nil
}

// GetBegin get db transaction
func GetBegin() *gorm.DB {
return db.GetManager().Begin()
Expand Down
49 changes: 0 additions & 49 deletions api/handler/LicenseHandler_test.go

This file was deleted.

183 changes: 0 additions & 183 deletions api/handler/eventLog_test.go

This file was deleted.

Loading

0 comments on commit e28a038

Please sign in to comment.