pkg/{timex,wait}: Unify code
This commit is contained in:
parent
59fff07b59
commit
8701fab93b
10 changed files with 77 additions and 74 deletions
|
|
@ -15,12 +15,14 @@ import (
|
|||
)
|
||||
|
||||
func (home *Home) updateInstances(ctx context.Context, io stream.IOStream) {
|
||||
timex.SetInterval(ctx, home.RefreshInterval, func(t time.Time) {
|
||||
io.Printf("[%s]: reloading instance list\n", t.Format(time.Stamp))
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
io.Printf("[%s]: reloading instance list\n", t.Format(time.Stamp))
|
||||
|
||||
names, _ := home.instanceMap()
|
||||
home.instanceNames.Set(names)
|
||||
})
|
||||
names, _ := home.instanceMap()
|
||||
home.instanceNames.Set(names)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (home *Home) instanceMap() (map[string]struct{}, error) {
|
||||
|
|
@ -37,12 +39,14 @@ func (home *Home) instanceMap() (map[string]struct{}, error) {
|
|||
}
|
||||
|
||||
func (home *Home) updateRender(ctx context.Context, io stream.IOStream) {
|
||||
timex.SetInterval(ctx, home.RefreshInterval, func(t time.Time) {
|
||||
io.Printf("[%s]: reloading home render\n", t.Format(time.Stamp))
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
io.Printf("[%s]: reloading home render\n", t.Format(time.Stamp))
|
||||
|
||||
bytes, _ := home.homeRender()
|
||||
home.homeBytes.Set(bytes)
|
||||
})
|
||||
bytes, _ := home.homeRender()
|
||||
home.homeBytes.Set(bytes)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
//go:embed "home.html"
|
||||
|
|
|
|||
|
|
@ -12,11 +12,14 @@ import (
|
|||
)
|
||||
|
||||
func (home *Home) updateRedirect(ctx context.Context, io stream.IOStream) {
|
||||
timex.SetInterval(ctx, home.RefreshInterval, func(t time.Time) {
|
||||
io.Printf("[%s]: reloading overrides\n", t.Format(time.Stamp))
|
||||
redirect, _ := home.loadRedirect()
|
||||
home.redirect.Set(&redirect)
|
||||
})
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
io.Printf("[%s]: reloading overrides\n", t.Format(time.Stamp))
|
||||
|
||||
redirect, _ := home.loadRedirect()
|
||||
home.redirect.Set(&redirect)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (home *Home) loadRedirect() (redirect Redirect, err error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue