Update to goprogram 0.1.0

This commit is contained in:
Tom Wiesing 2022-10-06 13:38:29 +02:00
parent d2d681a4f2
commit 7cda92b342
No known key found for this signature in database
31 changed files with 141 additions and 244 deletions

View file

@ -7,9 +7,9 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/slicesx"
"github.com/FAU-CDI/wisski-distillery/pkg/smartp"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/lib/collection"
"github.com/tkw1536/goprogram/status"
"github.com/tkw1536/goprogram/stream"
)
@ -46,13 +46,13 @@ func (bu blindUpdate) Run(context wisski_distillery.Context) error {
return err
}
if !bu.Force {
wissKIs = slicesx.Filter(wissKIs, func(instance instances.WissKI) bool {
wissKIs = collection.Filter(wissKIs, func(instance instances.WissKI) bool {
return bool(instance.AutoBlindUpdateEnabled)
})
}
// and do the actual blind_update!
return smartp.Run(context.IOStream, bu.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
return status.StreamGroup(context.IOStream, bu.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
code, err := instance.Shell(io, "/runtime/blind_update.sh")
if err != nil {
return errBlindUpdateFailed.WithMessageF(instance.Slug, environment.ExecCommandError)
@ -61,7 +61,7 @@ func (bu blindUpdate) Run(context wisski_distillery.Context) error {
return errBlindUpdateFailed.WithMessageF(instance.Slug, code)
}
return nil
}, wissKIs, smartp.SmartMessage(func(item instances.WissKI) string {
}, wissKIs, status.SmartMessage(func(item instances.WissKI) string {
return fmt.Sprintf("blind_update %q", item.Slug)
}))
}

View file

@ -6,8 +6,8 @@ import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/pkg/smartp"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/status"
"github.com/tkw1536/goprogram/stream"
)
@ -45,7 +45,7 @@ func (cr cron) Run(context wisski_distillery.Context) error {
}
// and do the actual blind_update!
return smartp.Run(context.IOStream, cr.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
return status.StreamGroup(context.IOStream, cr.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
code, err := instance.Shell(io, "/runtime/cron.sh")
if err != nil {
io.EPrintln(err)
@ -57,7 +57,7 @@ func (cr cron) Run(context wisski_distillery.Context) error {
}
return nil
}, wissKIs, smartp.SmartMessage(func(item instances.WissKI) string {
}, wissKIs, status.SmartMessage(func(item instances.WissKI) string {
return fmt.Sprintf("cron %q", item.Slug)
}))
}

View file

@ -5,7 +5,7 @@ import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/pkg/slicesx"
"github.com/tkw1536/goprogram/lib/collection"
)
// Info is then 'info' command
@ -72,7 +72,7 @@ func (i info) Run(context wisski_distillery.Context) error {
}
context.Printf("Pathbuilders: (count %d)\n", len(info.Pathbuilders))
slicesx.ForSorted(info.Pathbuilders, func(name, data string) {
collection.IterateSorted(info.Pathbuilders, func(name, data string) {
context.Printf("- %s (%d bytes)\n", name, len(data))
})

View file

@ -6,8 +6,8 @@ import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/pkg/smartp"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/status"
"github.com/tkw1536/goprogram/stream"
)
@ -46,9 +46,9 @@ func (rb rebuild) Run(context wisski_distillery.Context) error {
}
// and do the actual rebuild
return smartp.Run(context.IOStream, rb.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
return status.StreamGroup(context.IOStream, rb.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
return instance.Build(io, true)
}, wissKIs, smartp.SmartMessage(func(item instances.WissKI) string {
}, wissKIs, status.SmartMessage(func(item instances.WissKI) string {
return fmt.Sprintf("rebuild %q", item.Slug)
}))
}

View file

@ -33,7 +33,7 @@ var errServerListen = exit.Error{
func (s server) Run(context wisski_distillery.Context) error {
dis := context.Environment
handler, err := dis.Control().Server(context.IOStream)
handler, err := dis.Control().Server(dis.Context(), context.IOStream)
if err != nil {
return err
}
@ -46,6 +46,11 @@ func (s server) Run(context wisski_distillery.Context) error {
return errServerListen.Wrap(err)
}
go func() {
<-dis.Context().Done()
listener.Close()
}()
// and serve that listener
err = http.Serve(listener, http.StripPrefix(s.Prefix, handler))
if err == nil {

View file

@ -6,8 +6,9 @@ import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/FAU-CDI/wisski-distillery/pkg/smartp"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/status"
"github.com/tkw1536/goprogram/stream"
)
@ -41,14 +42,14 @@ func (upc updateprefixconfig) Run(context wisski_distillery.Context) error {
return errPrefixUpdateFailed.Wrap(err)
}
return smartp.Run(context.IOStream, upc.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
return status.StreamGroup(context.IOStream, upc.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
io.Println("reading prefixes")
err := instance.UpdatePrefixes()
if err != nil {
return errPrefixUpdateFailed.Wrap(err)
}
return nil
}, wissKIs, smartp.SmartMessage(func(item instances.WissKI) string {
}, wissKIs, status.SmartMessage(func(item instances.WissKI) string {
return fmt.Sprintf("update_prefix %q", item.Slug)
}))
}