crontab.go 703 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package cmd
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/config"
  6. "kpt-pasture/store/kptstore"
  7. "gitee.com/xuyiping_admin/pkg/cmd"
  8. "github.com/spf13/cobra"
  9. )
  10. // CrontabCmd represents the crontab command
  11. var CrontabCmd = &cobra.Command{
  12. Use: "crontab",
  13. Short: "计划任务",
  14. Run: func(cmd *cobra.Command, args []string) {
  15. fmt.Println("crontab called")
  16. },
  17. }
  18. func init() {
  19. // 每日同步脚本
  20. cmd.Instant(JobCmd, "update:cowAge", UpdateCowDayAge, "更新牛只日龄")
  21. }
  22. func UpdateCowDayAge(ctx context.Context, args []string) error {
  23. cfg := config.Options()
  24. db := kptstore.MustMigrateStore(cfg)
  25. sqlDB, err := db.DB()
  26. if err != nil {
  27. panic(err)
  28. }
  29. defer sqlDB.Close()
  30. return nil
  31. }