add configuration

This commit is contained in:
Pijus Kamandulis
2025-05-27 21:56:19 +03:00
parent d836830f45
commit 1cc12afa16
6 changed files with 79 additions and 24 deletions

View File

@@ -18,17 +18,26 @@ import (
const logsDir = "/home/pk/pro/pkstats/logs"
func WatchAndIngest(db *clover.DB) {
type Ingestor struct {
db *clover.DB
logPath string
}
func NewIngestor(db *clover.DB, path string) *Ingestor {
return &Ingestor{db: db, logPath: path}
}
func (this *Ingestor) WatchAndIngest() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
<-ticker.C
IngestClosedBlocks(db)
this.ingestClosedBlocks()
}
}
func IngestClosedBlocks(db *clover.DB) {
func (this *Ingestor) ingestClosedBlocks() {
entries, err := os.ReadDir(logsDir)
if err != nil {
log.Println("Error reading logsDir:", err)
@@ -54,12 +63,12 @@ func IngestClosedBlocks(db *clover.DB) {
// Ingest all except last (current block dir)
for _, dir := range blockDirs[:len(blockDirs)-1] {
IngestBlockDir(db, filepath.Join(logsDir, dir.Name()))
this.ingestBlockDir(this.db, filepath.Join(logsDir, dir.Name()))
_ = os.RemoveAll(filepath.Join(logsDir, dir.Name()))
}
}
func IngestBlockDir(db *clover.DB, dirPath string) {
func (this *Ingestor) ingestBlockDir(db *clover.DB, dirPath string) {
files, err := os.ReadDir(dirPath)
if err != nil {
log.Printf("Failed to read block dir %s: %v", dirPath, err)