Mining/pkg/database/interface.go
Virgil 976ff0141c
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
refactor(ax): tighten remaining naming and docs
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-04 05:08:34 +00:00

95 lines
2.9 KiB
Go

package database
import (
"context"
"time"
)
// var store database.HashrateStore = database.DefaultStore()
// store.InsertHashratePoint(ctx, "xmrig", "xmrig", point, database.ResolutionHigh)
// store.Cleanup(30)
type HashrateStore interface {
// store.InsertHashratePoint(ctx, "xmrig", "xmrig", HashratePoint{Timestamp: time.Now(), Hashrate: 1234}, ResolutionHigh)
InsertHashratePoint(ctx context.Context, minerName, minerType string, point HashratePoint, resolution Resolution) error
// points, err := store.GetHashrateHistory("xmrig", ResolutionHigh, time.Now().Add(-time.Hour), time.Now())
GetHashrateHistory(minerName string, resolution Resolution, since, until time.Time) ([]HashratePoint, error)
// stats, err := store.GetHashrateStats("xmrig")
// if stats != nil { logging.Info("stats", logging.Fields{"average": stats.AverageRate}) }
GetHashrateStats(minerName string) (*HashrateStats, error)
// allStats, err := store.GetAllMinerStats()
// for _, stats := range allStats { logging.Info("stats", logging.Fields{"miner": stats.MinerName}) }
GetAllMinerStats() ([]HashrateStats, error)
// store.Cleanup(30) // remove data older than 30 days
Cleanup(retentionDays int) error
// store.Close()
Close() error
}
// store := database.DefaultStore()
type defaultStore struct{}
// store := database.DefaultStore()
// store.GetHashrateStats("xmrig")
func DefaultStore() HashrateStore {
return &defaultStore{}
}
func (store *defaultStore) InsertHashratePoint(ctx context.Context, minerName, minerType string, point HashratePoint, resolution Resolution) error {
return InsertHashratePoint(ctx, minerName, minerType, point, resolution)
}
func (store *defaultStore) GetHashrateHistory(minerName string, resolution Resolution, since, until time.Time) ([]HashratePoint, error) {
return GetHashrateHistory(minerName, resolution, since, until)
}
func (store *defaultStore) GetHashrateStats(minerName string) (*HashrateStats, error) {
return GetHashrateStats(minerName)
}
func (store *defaultStore) GetAllMinerStats() ([]HashrateStats, error) {
return GetAllMinerStats()
}
func (store *defaultStore) Cleanup(retentionDays int) error {
return Cleanup(retentionDays)
}
func (store *defaultStore) Close() error {
return Close()
}
// store := database.NopStore()
func NopStore() HashrateStore {
return &nopStore{}
}
type nopStore struct{}
func (store *nopStore) InsertHashratePoint(ctx context.Context, minerName, minerType string, point HashratePoint, resolution Resolution) error {
return nil
}
func (store *nopStore) GetHashrateHistory(minerName string, resolution Resolution, since, until time.Time) ([]HashratePoint, error) {
return nil, nil
}
func (store *nopStore) GetHashrateStats(minerName string) (*HashrateStats, error) {
return nil, nil
}
func (store *nopStore) GetAllMinerStats() ([]HashrateStats, error) {
return nil, nil
}
func (store *nopStore) Cleanup(retentionDays int) error {
return nil
}
func (store *nopStore) Close() error {
return nil
}