try a way to track the times so they can be throttled
This commit is contained in:
parent
7c37e3841a
commit
f7b5e1a83e
|
@ -8,8 +8,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Forge) ConfigSave() error {
|
func (f *Forge) ConfigSave() error {
|
||||||
|
@ -28,6 +30,11 @@ func (f *Forge) ConfigSave() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if f.Repos != nil {
|
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 {
|
if e := f.Repos.ConfigSave(); e != nil {
|
||||||
log.Info("forge.Repos.ConfigSave() error", e)
|
log.Info("forge.Repos.ConfigSave() error", e)
|
||||||
err = e
|
err = e
|
||||||
|
|
18
init.go
18
init.go
|
@ -40,18 +40,29 @@ func Init() *Forge {
|
||||||
|
|
||||||
f.Machine.InitWit()
|
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()
|
now := time.Now()
|
||||||
start := f.Repos.Len()
|
start := f.Repos.Len()
|
||||||
f.ScanGoSrc()
|
f.ScanGoSrc()
|
||||||
|
f.FullScanRan()
|
||||||
end := f.Repos.Len()
|
end := f.Repos.Len()
|
||||||
if (end - start) == 0 {
|
if (end - start) == 0 {
|
||||||
log.Log(INFO, "forgepb.Scan() Scan did not find new git repositories. Total =", end)
|
log.Log(INFO, "forgepb.Scan() Scan did not find new git repositories. Total =", end)
|
||||||
|
if f.FullScanAge() > time.Minute {
|
||||||
|
f.rillUpdate(20, 10)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Log(INFO, "forgepb.Scan() Scan found", end-start, "new git repositories. Total =", end)
|
log.Log(INFO, "forgepb.Scan() Scan found", end-start, "new git repositories. Total =", end)
|
||||||
|
f.rillUpdate(20, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.rillUpdate(20, 10)
|
|
||||||
|
|
||||||
if f.configSave {
|
if f.configSave {
|
||||||
// taking this out to debug Marshal() panic
|
// taking this out to debug Marshal() panic
|
||||||
// os.Exit(-1)
|
// os.Exit(-1)
|
||||||
|
@ -108,6 +119,9 @@ func (f *Forge) InitPB() {
|
||||||
}
|
}
|
||||||
f.Repos = gitpb.NewRepos()
|
f.Repos = gitpb.NewRepos()
|
||||||
f.Repos.ConfigLoad()
|
f.Repos.ConfigLoad()
|
||||||
|
if f.Repos.HasFullScan {
|
||||||
|
f.hasFullScan = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only init's the protobuf. intended to not scan or change anything
|
// only init's the protobuf. intended to not scan or change anything
|
||||||
|
|
33
structs.go
33
structs.go
|
@ -2,6 +2,7 @@ package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sync "sync"
|
sync "sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
|
@ -10,15 +11,16 @@ import (
|
||||||
// maybe an interface someday?
|
// maybe an interface someday?
|
||||||
type Forge struct {
|
type Forge struct {
|
||||||
// one-time initialized data
|
// one-time initialized data
|
||||||
initOnce sync.Once
|
initOnce sync.Once
|
||||||
initErr error // init error, if any
|
initErr error // init error, if any
|
||||||
|
goSrc string // the path to go/src
|
||||||
goSrc string // the path to go/src
|
goWork bool // means the user is currently using a go.work file
|
||||||
goWork bool // means the user is currently using a go.work file
|
Config *ForgeConfigs // config repos for readonly, private, etc
|
||||||
Config *ForgeConfigs // config repos for readonly, private, etc
|
Repos *gitpb.Repos // the repo protobufs
|
||||||
Repos *gitpb.Repos
|
Machine *zoopb.Machine // things for virtigo to track vm's
|
||||||
Machine *zoopb.Machine
|
configSave bool // if you need to save the config because things changed
|
||||||
configSave bool
|
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 {
|
func (f *Forge) GetGoSrc() string {
|
||||||
|
@ -28,3 +30,16 @@ func (f *Forge) GetGoSrc() string {
|
||||||
func (f *Forge) IsGoWork() bool {
|
func (f *Forge) IsGoWork() bool {
|
||||||
return f.goWork
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue