wdcli: Use progress writer instead of IOStream
This commit is contained in:
parent
890022ae64
commit
3b78b06fff
49 changed files with 396 additions and 393 deletions
|
|
@ -3,13 +3,13 @@ package home
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
type Home struct {
|
||||
|
|
@ -30,10 +30,10 @@ var (
|
|||
|
||||
func (*Home) Routes() []string { return []string{"/"} }
|
||||
|
||||
func (home *Home) Handler(ctx context.Context, route string, io stream.IOStream) (http.Handler, error) {
|
||||
home.updateRedirect(ctx, io)
|
||||
home.updateInstances(ctx, io)
|
||||
home.updateRender(ctx, io)
|
||||
func (home *Home) Handler(ctx context.Context, route string, progress io.Writer) (http.Handler, error) {
|
||||
home.updateRedirect(ctx, progress)
|
||||
home.updateInstances(ctx, progress)
|
||||
home.updateRender(ctx, progress)
|
||||
return home, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package home
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
_ "embed"
|
||||
|
|
@ -10,14 +12,13 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func (home *Home) updateInstances(ctx context.Context, io stream.IOStream) {
|
||||
func (home *Home) updateInstances(ctx context.Context, progress io.Writer) {
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
io.Printf("[%s]: reloading instance list\n", t.Format(time.Stamp))
|
||||
fmt.Fprintf(progress, "[%s]: reloading instance list\n", t.Format(time.Stamp))
|
||||
|
||||
err := (func() error {
|
||||
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
|
||||
|
|
@ -32,7 +33,7 @@ func (home *Home) updateInstances(ctx context.Context, io stream.IOStream) {
|
|||
return nil
|
||||
})()
|
||||
if err != nil {
|
||||
io.EPrintf("error reloading instances: ", err.Error())
|
||||
fmt.Fprintf(progress, "error reloading instances: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
@ -51,10 +52,10 @@ func (home *Home) instanceMap(ctx context.Context) (map[string]struct{}, error)
|
|||
return names, nil
|
||||
}
|
||||
|
||||
func (home *Home) updateRender(ctx context.Context, io stream.IOStream) {
|
||||
func (home *Home) updateRender(ctx context.Context, progress io.Writer) {
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
io.Printf("[%s]: reloading home render list\n", t.Format(time.Stamp))
|
||||
fmt.Fprintf(progress, "[%s]: reloading home render list\n", t.Format(time.Stamp))
|
||||
|
||||
err := (func() error {
|
||||
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
|
||||
|
|
@ -69,7 +70,7 @@ func (home *Home) updateRender(ctx context.Context, io stream.IOStream) {
|
|||
return nil
|
||||
})()
|
||||
if err != nil {
|
||||
io.EPrintf("error reloading instances: ", err.Error())
|
||||
fmt.Fprintf(progress, "error reloading instances: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -3,18 +3,19 @@ package home
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
func (home *Home) updateRedirect(ctx context.Context, io stream.IOStream) {
|
||||
func (home *Home) updateRedirect(ctx context.Context, progress io.Writer) {
|
||||
go func() {
|
||||
for t := range timex.TickContext(ctx, home.RefreshInterval) {
|
||||
io.Printf("[%s]: reloading overrides\n", t.Format(time.Stamp))
|
||||
fmt.Fprintf(progress, "[%s]: reloading overrides\n", t.Format(time.Stamp))
|
||||
|
||||
err := (func() error {
|
||||
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
|
||||
|
|
@ -29,7 +30,7 @@ func (home *Home) updateRedirect(ctx context.Context, io stream.IOStream) {
|
|||
return nil
|
||||
})()
|
||||
if err != nil {
|
||||
io.EPrintf("error reloading overrides: ", err.Error())
|
||||
fmt.Fprintf(progress, "error reloading overrides: %s", err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue