优化节点分配逻辑,使用 edge id 固定轮换顺位;日志与 journal 集成;完善命令执行后的资源清理
This commit is contained in:
@@ -2,9 +2,10 @@ package actions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"zzman/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"zzman/model"
|
||||
)
|
||||
|
||||
const batchSize = 1000
|
||||
@@ -18,9 +19,9 @@ func FindEdgesByCity(tx *gorm.DB, cityId int) ([]model.Edge, error) {
|
||||
return edges, nil
|
||||
}
|
||||
|
||||
func SliceActiveEdgesByCity(tx *gorm.DB, cityId int, offset int, limit int) ([]model.Edge, error) {
|
||||
func SliceActiveEdges(tx *gorm.DB, cityId int, afterEdgeId int, count int) ([]model.Edge, error) {
|
||||
var edges []model.Edge
|
||||
err := tx.Limit(limit).Offset(offset).Find(&edges, "city_id = ? and active = 1", cityId).Error
|
||||
err := tx.Limit(count).Find(&edges, "id > ? and city_id = ? and active = 1", afterEdgeId, cityId).Error
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find edges with offset: %w", err)
|
||||
}
|
||||
@@ -34,10 +35,7 @@ func SaveEdges(tx *gorm.DB, edges []model.Edge) error {
|
||||
|
||||
// 分批处理边缘设备数据
|
||||
for i := 0; i < len(edges); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(edges) {
|
||||
end = len(edges)
|
||||
}
|
||||
end := min(i+batchSize, len(edges))
|
||||
|
||||
batch := edges[i:end]
|
||||
err := tx.Clauses(clause.OnConflict{
|
||||
|
||||
Reference in New Issue
Block a user