Do a large chunk of the move to go
This commit moves a huge chunk of the code to go. The TODO.md document indicates what is left to be done.
This commit is contained in:
parent
db2ad9b4bd
commit
7b38fdd801
93 changed files with 4689 additions and 645 deletions
55
cmd/cron.go
Normal file
55
cmd/cron.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/env"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/logging"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
// Cron is the 'cron' command
|
||||
var Cron wisski_distillery.Command = cron{}
|
||||
|
||||
type cron struct {
|
||||
Positionals struct {
|
||||
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run cron in"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
func (cron) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: env.Requirements{
|
||||
NeedsConfig: true,
|
||||
},
|
||||
Command: "cron",
|
||||
Description: "Runs the cron script for several instances",
|
||||
}
|
||||
}
|
||||
|
||||
var errCronFailed = exit.Error{
|
||||
Message: "Failed to run cron script for instance %q: exited with code %s",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
func (cr cron) Run(context wisski_distillery.Context) error {
|
||||
instances, err := context.Environment.Instances(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 := instance.Shell(context.IOStream, "/utils/cron.sh")
|
||||
if code != 0 {
|
||||
// keep going, because we want to run as many crons as possible
|
||||
err = errBlindUpdateFailed.WithMessageF(instance.Slug, code)
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "running cron for instance %s", instance.Slug)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue