Compare commits

..

4 Commits

Author SHA1 Message Date
Frederik Ring
7cfea62933 Hoist control for exiting script a level up (#348)
* Hoist control for exiting script a level up

* Do not accidentally nil out errors

* Log when running schedule

* Remove duplicate log line

* Warn on cron schedule that will never run
2024-02-09 10:24:28 +01:00
Frederik Ring
d14e826529 Tidy go.mod 2024-02-07 17:57:59 +01:00
Frederik Ring
21191d601a Entrypoint script is not needed anymore (#346) 2024-02-06 21:46:18 +01:00
pixxon
d642a60c4d Move cron scheduling inside application (#338)
* Move cron scheduling inside application

* Make envvar a fallback and check for errors

* Panic significantly less

* propagate error out of runBackup

* Add structured logging

* FIx error propagation to exit

* Enable the new scheduler by default

* Review fixes

* Added docs and better error propagation
2024-02-06 21:05:38 +01:00
2 changed files with 2 additions and 32 deletions

View File

@@ -9,7 +9,6 @@ import (
"log/slog"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/robfig/cron/v3"
@@ -123,7 +122,7 @@ func runScript(c *Config) (err error) {
return runErr
}
func (c *command) runInForeground(profileCronExpression string) error {
func (c *command) runInForeground() error {
cr := cron.New(
cron.WithParser(
cron.NewParser(
@@ -190,28 +189,6 @@ func (c *command) runInForeground(profileCronExpression string) error {
}
}
if profileCronExpression != "" {
if _, err := cr.AddFunc(profileCronExpression, func() {
memStats := runtime.MemStats{}
runtime.ReadMemStats(&memStats)
c.logger.Info(
"Collecting runtime information",
"num_goroutines",
runtime.NumGoroutine(),
"memory_heap_alloc",
formatBytes(memStats.HeapAlloc, false),
"memory_heap_inuse",
formatBytes(memStats.HeapInuse, false),
"memory_heap_sys",
formatBytes(memStats.HeapSys, false),
"memory_heap_objects",
memStats.HeapObjects,
)
}); err != nil {
return fmt.Errorf("runInForeground: error adding profiling job: %w", err)
}
}
var quit = make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGTERM, syscall.SIGINT)
cr.Start()
@@ -237,12 +214,11 @@ func (c *command) runAsCommand() error {
func main() {
foreground := flag.Bool("foreground", false, "run the tool in the foreground")
profile := flag.String("profile", "", "collect runtime metrics and log them periodically on the given cron expression")
flag.Parse()
c := newCommand()
if *foreground {
c.must(c.runInForeground(*profile))
c.must(c.runInForeground())
} else {
c.must(c.runAsCommand())
}

View File

@@ -112,12 +112,6 @@ func newScript(c *Config) (*script, error) {
return nil, fmt.Errorf("newScript: failed to create docker client")
}
s.cli = cli
s.registerHook(hookLevelPlumbing, func(err error) error {
if err := s.cli.Close(); err != nil {
return fmt.Errorf("newScript: failed to close docker client: %w", err)
}
return nil
})
}
logFunc := func(logType storage.LogLevel, context string, msg string, params ...any) {