diff --git a/cmd/blind_update.go b/cmd/blind_update.go index a91c216..6aaaf33 100644 --- a/cmd/blind_update.go +++ b/cmd/blind_update.go @@ -17,7 +17,7 @@ import ( var BlindUpdate wisski_distillery.Command = blindUpdate{} type blindUpdate struct { - Parallel int `short:"p" long:"parallel" description:"run on (at most) this many instances concurrently. 0 for no limit." default:"1"` + Parallel int `short:"p" long:"parallel" description:"run on (at most) this many instances in parallel. 0 for no limit." default:"1"` Force bool `short:"f" long:"force" description:"force running blind-update even if AutoBlindUpdate is set to false"` Positionals struct { Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run blind-update in"` diff --git a/cmd/cron.go b/cmd/cron.go index 8fe75f0..24fd9fc 100644 --- a/cmd/cron.go +++ b/cmd/cron.go @@ -1,16 +1,22 @@ package cmd import ( + "fmt" + 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/logging" + "github.com/FAU-CDI/wisski-distillery/pkg/smartp" "github.com/tkw1536/goprogram/exit" + "github.com/tkw1536/goprogram/stream" ) // Cron is the 'cron' command var Cron wisski_distillery.Command = cron{} type cron struct { + Parallel int `short:"p" long:"parallel" description:"run on (at most) this many instances in parallel. 0 for no limit." default:"1"` + Positionals struct { Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run cron in"` } `positional-args:"true"` @@ -32,27 +38,26 @@ var errCronFailed = exit.Error{ } func (cr cron) Run(context wisski_distillery.Context) error { - instances, err := context.Environment.Instances().Load(cr.Positionals.Slug...) + // find all the instances! + wissKIs, err := context.Environment.Instances().Load(cr.Positionals.Slug...) if err != nil { return err } - // iterate over the instances and store the last value of error - for _, instance := range instances { - logging.LogOperation(func() error { - code, err := instance.Shell(context.IOStream, "/runtime/cron.sh") - if err != nil { - context.EPrintln(err) - } - if code != 0 { - // keep going, because we want to run as many crons as possible - err = errBlindUpdateFailed.WithMessageF(instance.Slug, code) - context.EPrintln(err) - } + // and do the actual blind_update! + return smartp.Run(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) + } + if code != 0 { + // keep going, because we want to run as many crons as possible + err = errBlindUpdateFailed.WithMessageF(instance.Slug, code) + io.EPrintln(err) + } - return nil - }, context.IOStream, "running cron for instance %s", instance.Slug) - } - - return err + return nil + }, wissKIs, smartp.SmartMessage(func(item instances.WissKI) string { + return fmt.Sprintf("cron %q", item.Slug) + })) } diff --git a/cmd/rebuild.go b/cmd/rebuild.go index 2e86974..a9aa7aa 100644 --- a/cmd/rebuild.go +++ b/cmd/rebuild.go @@ -1,16 +1,21 @@ package cmd import ( + "fmt" + 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/logging" + "github.com/FAU-CDI/wisski-distillery/pkg/smartp" "github.com/tkw1536/goprogram/exit" + "github.com/tkw1536/goprogram/stream" ) // Cron is the 'cron' command var Rebuild wisski_distillery.Command = rebuild{} type rebuild struct { + Parallel int `short:"p" long:"parallel" description:"run on (at most) this many instances in parallel. 0 for no limit." default:"1"` Positionals struct { Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run rebuild"` } `positional-args:"true"` @@ -34,18 +39,16 @@ var errRebuildFailed = exit.Error{ func (rb rebuild) Run(context wisski_distillery.Context) error { dis := context.Environment - instances, err := dis.Instances().Load(rb.Positionals.Slug...) + // find the instances + wissKIs, err := dis.Instances().Load(rb.Positionals.Slug...) if err != nil { return err } - // iterate over the instances and store the last value of error - var globalErr error - for _, instance := range instances { - logging.LogOperation(func() error { - return instance.Build(context.IOStream, true) - }, context.IOStream, "Rebuilding instance %s", instance.Slug) - } - - return globalErr + // and do the actual rebuild + return smartp.Run(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 { + return fmt.Sprintf("rebuild %q", item.Slug) + })) }