cmd/{cron,rebuild}: Add parallel argument
This commit is contained in:
parent
2639cda69b
commit
f6f24670c2
3 changed files with 39 additions and 31 deletions
|
|
@ -17,7 +17,7 @@ import (
|
||||||
var BlindUpdate wisski_distillery.Command = blindUpdate{}
|
var BlindUpdate wisski_distillery.Command = blindUpdate{}
|
||||||
|
|
||||||
type blindUpdate struct {
|
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"`
|
Force bool `short:"f" long:"force" description:"force running blind-update even if AutoBlindUpdate is set to false"`
|
||||||
Positionals struct {
|
Positionals struct {
|
||||||
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run blind-update in"`
|
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run blind-update in"`
|
||||||
|
|
|
||||||
43
cmd/cron.go
43
cmd/cron.go
|
|
@ -1,16 +1,22 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
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/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/exit"
|
||||||
|
"github.com/tkw1536/goprogram/stream"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cron is the 'cron' command
|
// Cron is the 'cron' command
|
||||||
var Cron wisski_distillery.Command = cron{}
|
var Cron wisski_distillery.Command = cron{}
|
||||||
|
|
||||||
type cron struct {
|
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 {
|
Positionals struct {
|
||||||
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run cron in"`
|
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run cron in"`
|
||||||
} `positional-args:"true"`
|
} `positional-args:"true"`
|
||||||
|
|
@ -32,27 +38,26 @@ var errCronFailed = exit.Error{
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr cron) Run(context wisski_distillery.Context) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over the instances and store the last value of error
|
// and do the actual blind_update!
|
||||||
for _, instance := range instances {
|
return smartp.Run(context.IOStream, cr.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
|
||||||
logging.LogOperation(func() error {
|
code, err := instance.Shell(io, "/runtime/cron.sh")
|
||||||
code, err := instance.Shell(context.IOStream, "/runtime/cron.sh")
|
if err != nil {
|
||||||
if err != nil {
|
io.EPrintln(err)
|
||||||
context.EPrintln(err)
|
}
|
||||||
}
|
if code != 0 {
|
||||||
if code != 0 {
|
// keep going, because we want to run as many crons as possible
|
||||||
// keep going, because we want to run as many crons as possible
|
err = errBlindUpdateFailed.WithMessageF(instance.Slug, code)
|
||||||
err = errBlindUpdateFailed.WithMessageF(instance.Slug, code)
|
io.EPrintln(err)
|
||||||
context.EPrintln(err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, context.IOStream, "running cron for instance %s", instance.Slug)
|
}, wissKIs, smartp.SmartMessage(func(item instances.WissKI) string {
|
||||||
}
|
return fmt.Sprintf("cron %q", item.Slug)
|
||||||
|
}))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,21 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
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/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/exit"
|
||||||
|
"github.com/tkw1536/goprogram/stream"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cron is the 'cron' command
|
// Cron is the 'cron' command
|
||||||
var Rebuild wisski_distillery.Command = rebuild{}
|
var Rebuild wisski_distillery.Command = rebuild{}
|
||||||
|
|
||||||
type rebuild struct {
|
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 {
|
Positionals struct {
|
||||||
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run rebuild"`
|
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run rebuild"`
|
||||||
} `positional-args:"true"`
|
} `positional-args:"true"`
|
||||||
|
|
@ -34,18 +39,16 @@ var errRebuildFailed = exit.Error{
|
||||||
func (rb rebuild) Run(context wisski_distillery.Context) error {
|
func (rb rebuild) Run(context wisski_distillery.Context) error {
|
||||||
dis := context.Environment
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over the instances and store the last value of error
|
// and do the actual rebuild
|
||||||
var globalErr error
|
return smartp.Run(context.IOStream, rb.Parallel, func(instance instances.WissKI, io stream.IOStream) error {
|
||||||
for _, instance := range instances {
|
return instance.Build(io, true)
|
||||||
logging.LogOperation(func() error {
|
}, wissKIs, smartp.SmartMessage(func(item instances.WissKI) string {
|
||||||
return instance.Build(context.IOStream, true)
|
return fmt.Sprintf("rebuild %q", item.Slug)
|
||||||
}, context.IOStream, "Rebuilding instance %s", instance.Slug)
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
return globalErr
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue