other.go 499 B

1234567891011121314151617181920212223
  1. package crontab
  2. import (
  3. "errors"
  4. "kpt-pasture/model"
  5. "time"
  6. "gorm.io/gorm"
  7. )
  8. // CreateCrontabLog 生成日志记录
  9. func (e *Entry) CreateCrontabLog(name string) bool {
  10. currDateTime := time.Now().Format(model.LayoutDate2)
  11. newCronLog := &model.CronLog{}
  12. if err := e.DB.Where("name = ?", name).
  13. Where("date = ?", currDateTime).First(newCronLog).Error; err != nil {
  14. if errors.Is(err, gorm.ErrRecordNotFound) {
  15. e.DB.Create(model.NewCronLog(name))
  16. return true
  17. }
  18. }
  19. return false
  20. }