Skip to content

Commit

Permalink
refactor: add log
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq authored and hulongjun committed Jan 6, 2025
2 parents 7f67919 + efbe566 commit 2d1022e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-version: 1.19

- name: docker-compose
run: docker-compose -f tests/docker-compose.yaml up -d
run: docker compose -f tests/docker-compose.yaml up -d

- uses: actions/cache@v3
with:
Expand Down
50 changes: 23 additions & 27 deletions internal/pkg/service/appevent/appevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package appevent
import (
"context"
"encoding/json"
"github.com/douyu/jupiter/pkg/store/gorm"
"github.com/douyu/jupiter/pkg/xlog"
"go.uber.org/zap"
"strings"
"time"

Expand All @@ -27,15 +30,14 @@ type appEvent struct {
topic string
}

func InitAppEvent(eventProducer *rocketmq.Producer, topic string) *appEvent {
func InitAppEvent(eventProducer *rocketmq.Producer, topic string) {
obj := &appEvent{
eventChan: make(chan db.AppEvent, 10000),
eventProducer: eventProducer,
topic: topic,
}
go obj.ConsumeEvent()
AppEvent = obj
return obj
}

func (a *appEvent) PutEvent(event db.AppEvent) {
Expand All @@ -57,33 +59,27 @@ func (a *appEvent) ConsumeEvent() {
}

func (a *appEvent) insert(event db.AppEvent) error {
tx := invoker.JunoMysql.Begin()
if err := tx.Create(&event).Error; err != nil {
tx.Rollback()
return err
}

if cfg.Cfg.JunoEvent.Rocketmq.Enable {
event.HandleOperationName()
event.HandleSourceName()
msg := &eventMessage{AppEvent: event, HostName: strings.Split(event.HostName, ",")}
eventMsg, _ := json.Marshal(&msg)
ctx, cancelFn := context.WithTimeout(context.Background(), time.Second)
_, err := a.eventProducer.SendSync(ctx, primitive.NewMessage(a.topic, eventMsg))
cancelFn()
if err != nil {
tx.Rollback()
err := invoker.JunoMysql.Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&event).Error; err != nil {
xlog.Error("app event insert err", zap.Error(err))
return err
}
}

err := tx.Commit().Error
if err != nil {
return err
}

//invoker.AppStatic.WithLabelValues(event.App, event.Source, event.Operation).Inc()
return nil
if cfg.Cfg.JunoEvent.Rocketmq.Enable {
event.HandleOperationName()
event.HandleSourceName()
msg := &eventMessage{AppEvent: event, HostName: strings.Split(event.HostName, ",")}
eventMsg, _ := json.Marshal(&msg)
ctx, cancelFn := context.WithTimeout(context.Background(), time.Second)
_, err := a.eventProducer.SendSync(ctx, primitive.NewMessage(a.topic, eventMsg))
cancelFn()
if err != nil {
xlog.Error("app event eventProducer err", zap.Error(err))
return err
}
}
return nil
})
return err
}

func (a *appEvent) List(param view.ReqEventList) (res []db.AppEvent, page *view.Pagination, err error) {
Expand Down
35 changes: 0 additions & 35 deletions internal/pkg/service/codeplatform/codeplatform_test.go

This file was deleted.

11 changes: 7 additions & 4 deletions internal/pkg/service/confgov2/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TryLock(uid, configId uint) (err error) {
config.LockUid = uid
now := time.Now()
config.LockAt = &now
err = tx.Save(&config).Error
err = tx.Table("configuration").Where("id = ?", config.ID).Updates(map[string]interface{}{"lock_uid": config.LockUid,
"lock_at": config.LockAt}).Error
if err != nil {
tx.Rollback()
return errors.Wrap(err, "获取编辑锁失败")
Expand All @@ -59,7 +60,8 @@ func Unlock(uid, configId uint) (err error) {

config.LockUid = 0
config.LockAt = nil
err = tx.Save(&config).Error
err = tx.Table("configuration").Where("id = ?", config.ID).Updates(map[string]interface{}{"lock_uid": config.LockUid,
"lock_at": config.LockAt}).Error
if err != nil {
tx.Rollback()
return errors.Wrap(err, "释放编辑锁失败")
Expand All @@ -68,7 +70,7 @@ func Unlock(uid, configId uint) (err error) {
return tx.Commit().Error
}

//clearLockPeriodically 定期清除编辑锁
// clearLockPeriodically 定期清除编辑锁
func clearLockPeriodically() {
var configs []db.Configuration

Expand All @@ -88,7 +90,8 @@ func clearLockPeriodically() {
for _, config := range configs {
config.LockAt = nil
config.LockUid = 0
tx.Save(&config)
tx.Table("configuration").Where("id = ?", config.ID).Updates(map[string]interface{}{"lock_uid": config.LockUid,
"lock_at": config.LockAt})
}
}
tx.Commit()
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
ports:
- 8080:8080
etcd:
image: "quay.io/coreos/etcd:v3.3"
image: "quay.io/coreos/etcd:v3.5.15"
environment:
ETCD_ADVERTISE_CLIENT_URLS: "http://0.0.0.0:2379"
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
Expand Down

0 comments on commit 2d1022e

Please sign in to comment.