try a way to track the times so they can be throttled

This commit is contained in:
Jeff Carr 2025-01-30 01:15:15 -06:00
parent 7c37e3841a
commit f7b5e1a83e
3 changed files with 47 additions and 11 deletions

View File

@ -8,8 +8,10 @@ import (
"fmt"
"os"
"path/filepath"
"time"
"go.wit.com/log"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
func (f *Forge) ConfigSave() error {
@ -28,6 +30,11 @@ func (f *Forge) ConfigSave() error {
}
}
if f.Repos != nil {
if f.HasFullScan() {
f.Repos.HasFullScan = true
t := time.Now()
f.Repos.FullScan = timestamppb.New(t)
}
if e := f.Repos.ConfigSave(); e != nil {
log.Info("forge.Repos.ConfigSave() error", e)
err = e

18
init.go
View File

@ -40,17 +40,28 @@ func Init() *Forge {
f.Machine.InitWit()
if f.hasFullScan {
// duplicate time checking below. which one to keep?
if f.FullScanAge() > time.Minute {
log.Log(INFO, "forgepb.Scan() skipping scan. been run a minute ago", f.FullScanAge())
return f
}
}
now := time.Now()
start := f.Repos.Len()
f.ScanGoSrc()
f.FullScanRan()
end := f.Repos.Len()
if (end - start) == 0 {
log.Log(INFO, "forgepb.Scan() Scan did not find new git repositories. Total =", end)
if f.FullScanAge() > time.Minute {
f.rillUpdate(20, 10)
}
} else {
log.Log(INFO, "forgepb.Scan() Scan found", end-start, "new git repositories. Total =", end)
}
f.rillUpdate(20, 10)
}
if f.configSave {
// taking this out to debug Marshal() panic
@ -108,6 +119,9 @@ func (f *Forge) InitPB() {
}
f.Repos = gitpb.NewRepos()
f.Repos.ConfigLoad()
if f.Repos.HasFullScan {
f.hasFullScan = true
}
}
// only init's the protobuf. intended to not scan or change anything

View File

@ -2,6 +2,7 @@ package forgepb
import (
sync "sync"
"time"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/zoopb"
@ -12,13 +13,14 @@ type Forge struct {
// one-time initialized data
initOnce sync.Once
initErr error // init error, if any
goSrc string // the path to go/src
goWork bool // means the user is currently using a go.work file
Config *ForgeConfigs // config repos for readonly, private, etc
Repos *gitpb.Repos
Machine *zoopb.Machine
configSave bool
Repos *gitpb.Repos // the repo protobufs
Machine *zoopb.Machine // things for virtigo to track vm's
configSave bool // if you need to save the config because things changed
hasFullScan bool // track last scan so it can be throttled
fullscan time.Time // time of the last scan so it can be throttled
}
func (f *Forge) GetGoSrc() string {
@ -28,3 +30,16 @@ func (f *Forge) GetGoSrc() string {
func (f *Forge) IsGoWork() bool {
return f.goWork
}
func (f *Forge) HasFullScan() bool {
return f.Repos.HasFullScan
}
func (f *Forge) FullScanRan() {
f.fullscan = time.Now()
}
func (f *Forge) FullScanAge() time.Duration {
fs := f.Repos.FullScan.AsTime()
return time.Since(fs)
}