gomanager/cmd/cron.go

49 lines
1.2 KiB
Go
Raw Permalink Normal View History

2023-12-01 23:02:33 +01:00
package cmd
import (
"fmt"
2024-01-08 16:54:54 +01:00
"log"
2023-12-01 23:02:33 +01:00
"runtime"
"code.icod.de/dalu/gomanager/ent"
"code.icod.de/dalu/gomanager/runner"
"github.com/spf13/cobra"
_ "github.com/mattn/go-sqlite3"
)
// cronCmd represents the cron command
var cronCmd = &cobra.Command{
Use: "cron",
Short: "this command is meant to be ran via cron",
RunE: func(cmd *cobra.Command, args []string) error {
runtime.GOMAXPROCS(1)
client, err := ent.Open("sqlite3", fmt.Sprintf("file:%s?mode=rwc&cache=private&_fk=1", sqliteFilename))
if err != nil {
return fmt.Errorf("failed opening connection to sqlite: %v", err)
}
2024-01-08 16:54:54 +01:00
defer func(client *ent.Client) {
err := client.Close()
if err != nil {
log.Println("error closing client", err.Error())
}
}(client)
2023-12-01 23:02:33 +01:00
r := runner.NewRunner(client)
return r.Run()
},
}
func init() {
rootCmd.AddCommand(cronCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// cronCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// cronCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}