mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-28 05:46:36 +08:00
refactor(repository): 收敛 model/repository 分层为唯一持久化入口
将 OpenFlare 与平台业务的数据访问从 model 与 apps 直连迁入 repository, model 仅保留实体与无 IO 规则;补充 code-check 架构守卫与开发规范。
This commit is contained in:
@@ -10,6 +10,8 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/Rain-kl/Wavelet/internal/repository"
|
||||
|
||||
"github.com/Rain-kl/Wavelet/internal/apps/openflare/chwriter"
|
||||
db "github.com/Rain-kl/Wavelet/internal/infra/persistence"
|
||||
"github.com/Rain-kl/Wavelet/internal/model"
|
||||
@@ -38,7 +40,7 @@ func run() error {
|
||||
|
||||
now := time.Now().UTC()
|
||||
nodeID := "e2e-app-" + now.Format("150405")
|
||||
if err := model.InsertOpenFlareMetricSnapshot(ctx, &model.OpenFlareMetricSnapshot{
|
||||
if err := repository.InsertOpenFlareMetricSnapshot(ctx, &model.OpenFlareMetricSnapshot{
|
||||
NodeID: nodeID, CapturedAt: now, CPUUsagePercent: 41.2,
|
||||
MemoryUsedBytes: 123, MemoryTotalBytes: 1000,
|
||||
StorageUsedBytes: 456, StorageTotalBytes: 2000,
|
||||
@@ -64,7 +66,7 @@ func run() error {
|
||||
func waitForSnapshot(ctx context.Context, nodeID string, now time.Time) error {
|
||||
deadline := time.Now().Add(flushWaitTimeout)
|
||||
for time.Now().Before(deadline) {
|
||||
rows, err := model.ListOpenFlareMetricSnapshotsSince(ctx, nodeID, now.Add(-time.Minute), listLimit)
|
||||
rows, err := repository.ListOpenFlareMetricSnapshotsSince(ctx, nodeID, now.Add(-time.Minute), listLimit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("list: %w", err)
|
||||
}
|
||||
@@ -78,7 +80,7 @@ func waitForSnapshot(ctx context.Context, nodeID string, now time.Time) error {
|
||||
}
|
||||
|
||||
func assertLatestIncludes(ctx context.Context, nodeID string, now time.Time) error {
|
||||
latest, err := model.ListOpenFlareLatestMetricSnapshotsSince(ctx, "", now.Add(-time.Hour))
|
||||
latest, err := repository.ListOpenFlareLatestMetricSnapshotsSince(ctx, "", now.Add(-time.Hour))
|
||||
if err != nil {
|
||||
return fmt.Errorf("latest: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user