重构通道管理逻辑,支持通过任务删除不同类型通道;引入 Asynq 处理异步任务;更新数据库结构以支持通道类型区分
This commit is contained in:
@@ -155,11 +155,20 @@ func (b *bill) fillFieldMap() {
|
||||
|
||||
func (b bill) clone(db *gorm.DB) bill {
|
||||
b.billDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
b.Trade.db = db.Session(&gorm.Session{Initialized: true})
|
||||
b.Trade.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
b.Refund.db = db.Session(&gorm.Session{Initialized: true})
|
||||
b.Refund.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
b.Resource.db = db.Session(&gorm.Session{Initialized: true})
|
||||
b.Resource.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return b
|
||||
}
|
||||
|
||||
func (b bill) replaceDB(db *gorm.DB) bill {
|
||||
b.billDo.ReplaceDB(db)
|
||||
b.Trade.db = db.Session(&gorm.Session{})
|
||||
b.Refund.db = db.Session(&gorm.Session{})
|
||||
b.Resource.db = db.Session(&gorm.Session{})
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -196,6 +205,11 @@ func (a billBelongsToTrade) Model(m *models.Bill) *billBelongsToTradeTx {
|
||||
return &billBelongsToTradeTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a billBelongsToTrade) Unscoped() *billBelongsToTrade {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billBelongsToTradeTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a billBelongsToTradeTx) Find() (result *models.Trade, err error) {
|
||||
@@ -234,6 +248,11 @@ func (a billBelongsToTradeTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a billBelongsToTradeTx) Unscoped() *billBelongsToTradeTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billBelongsToRefund struct {
|
||||
db *gorm.DB
|
||||
|
||||
@@ -267,6 +286,11 @@ func (a billBelongsToRefund) Model(m *models.Bill) *billBelongsToRefundTx {
|
||||
return &billBelongsToRefundTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a billBelongsToRefund) Unscoped() *billBelongsToRefund {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billBelongsToRefundTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a billBelongsToRefundTx) Find() (result *models.Refund, err error) {
|
||||
@@ -305,6 +329,11 @@ func (a billBelongsToRefundTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a billBelongsToRefundTx) Unscoped() *billBelongsToRefundTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billBelongsToResource struct {
|
||||
db *gorm.DB
|
||||
|
||||
@@ -345,6 +374,11 @@ func (a billBelongsToResource) Model(m *models.Bill) *billBelongsToResourceTx {
|
||||
return &billBelongsToResourceTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a billBelongsToResource) Unscoped() *billBelongsToResource {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billBelongsToResourceTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a billBelongsToResourceTx) Find() (result *models.Resource, err error) {
|
||||
@@ -383,6 +417,11 @@ func (a billBelongsToResourceTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a billBelongsToResourceTx) Unscoped() *billBelongsToResourceTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type billDo struct{ gen.DO }
|
||||
|
||||
func (b billDo) Debug() *billDo {
|
||||
|
||||
@@ -44,6 +44,7 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
_channel.EdgeHost = field.NewString(tableName, "edge_host")
|
||||
_channel.EdgeID = field.NewInt32(tableName, "edge_id")
|
||||
_channel.Whitelists = field.NewString(tableName, "whitelists")
|
||||
_channel.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
|
||||
_channel.fillFieldMap()
|
||||
|
||||
@@ -71,6 +72,7 @@ type channel struct {
|
||||
EdgeHost field.String // 节点地址
|
||||
EdgeID field.Int32 // 节点ID
|
||||
Whitelists field.String // IP白名单,逗号分隔
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -104,6 +106,7 @@ func (c *channel) updateTableName(table string) *channel {
|
||||
c.EdgeHost = field.NewString(table, "edge_host")
|
||||
c.EdgeID = field.NewInt32(table, "edge_id")
|
||||
c.Whitelists = field.NewString(table, "whitelists")
|
||||
c.ResourceID = field.NewInt32(table, "resource_id")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
@@ -120,7 +123,7 @@ func (c *channel) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (c *channel) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 17)
|
||||
c.fieldMap = make(map[string]field.Expr, 18)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["proxy_id"] = c.ProxyID
|
||||
@@ -138,6 +141,7 @@ func (c *channel) fillFieldMap() {
|
||||
c.fieldMap["edge_host"] = c.EdgeHost
|
||||
c.fieldMap["edge_id"] = c.EdgeID
|
||||
c.fieldMap["whitelists"] = c.Whitelists
|
||||
c.fieldMap["resource_id"] = c.ResourceID
|
||||
}
|
||||
|
||||
func (c channel) clone(db *gorm.DB) channel {
|
||||
|
||||
@@ -121,11 +121,14 @@ func (p *proxy) fillFieldMap() {
|
||||
|
||||
func (p proxy) clone(db *gorm.DB) proxy {
|
||||
p.proxyDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
p.Edges.db = db.Session(&gorm.Session{Initialized: true})
|
||||
p.Edges.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return p
|
||||
}
|
||||
|
||||
func (p proxy) replaceDB(db *gorm.DB) proxy {
|
||||
p.proxyDo.ReplaceDB(db)
|
||||
p.Edges.db = db.Session(&gorm.Session{})
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -162,6 +165,11 @@ func (a proxyHasManyEdges) Model(m *models.Proxy) *proxyHasManyEdgesTx {
|
||||
return &proxyHasManyEdgesTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdges) Unscoped() *proxyHasManyEdges {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type proxyHasManyEdgesTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a proxyHasManyEdgesTx) Find() (result []*models.Edge, err error) {
|
||||
@@ -200,6 +208,11 @@ func (a proxyHasManyEdgesTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdgesTx) Unscoped() *proxyHasManyEdgesTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type proxyDo struct{ gen.DO }
|
||||
|
||||
func (p proxyDo) Debug() *proxyDo {
|
||||
|
||||
@@ -121,11 +121,17 @@ func (r *resource) fillFieldMap() {
|
||||
|
||||
func (r resource) clone(db *gorm.DB) resource {
|
||||
r.resourceDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
r.Short.db = db.Session(&gorm.Session{Initialized: true})
|
||||
r.Short.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
r.Long.db = db.Session(&gorm.Session{Initialized: true})
|
||||
r.Long.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resource) replaceDB(db *gorm.DB) resource {
|
||||
r.resourceDo.ReplaceDB(db)
|
||||
r.Short.db = db.Session(&gorm.Session{})
|
||||
r.Long.db = db.Session(&gorm.Session{})
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -162,6 +168,11 @@ func (a resourceHasOneShort) Model(m *models.Resource) *resourceHasOneShortTx {
|
||||
return &resourceHasOneShortTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a resourceHasOneShort) Unscoped() *resourceHasOneShort {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceHasOneShortTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a resourceHasOneShortTx) Find() (result *models.ResourceShort, err error) {
|
||||
@@ -200,6 +211,11 @@ func (a resourceHasOneShortTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a resourceHasOneShortTx) Unscoped() *resourceHasOneShortTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceHasOneLong struct {
|
||||
db *gorm.DB
|
||||
|
||||
@@ -233,6 +249,11 @@ func (a resourceHasOneLong) Model(m *models.Resource) *resourceHasOneLongTx {
|
||||
return &resourceHasOneLongTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a resourceHasOneLong) Unscoped() *resourceHasOneLong {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceHasOneLongTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a resourceHasOneLongTx) Find() (result *models.ResourceLong, err error) {
|
||||
@@ -271,6 +292,11 @@ func (a resourceHasOneLongTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a resourceHasOneLongTx) Unscoped() *resourceHasOneLongTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type resourceDo struct{ gen.DO }
|
||||
|
||||
func (r resourceDo) Debug() *resourceDo {
|
||||
|
||||
Reference in New Issue
Block a user