fix: splitable not function due to empty datefield (#23913)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2025-12-09 13:33:54 +08:00
committed by GitHub
parent d50535b69c
commit 538e3b741c
2 changed files with 24 additions and 9 deletions

View File

@@ -70,15 +70,18 @@ func StartService() {
models.NotifyService.InitAll()
defer models.NotifyService.StopAll()
cron := cronman.InitCronJobManager(true, 2)
// update service
cron.AddJobAtIntervals("UpdateServices", time.Duration(opts.UpdateInterval)*time.Minute, models.NotifyService.UpdateServices)
if !opts.IsSlaveNode {
cron := cronman.InitCronJobManager(true, opts.CronJobWorkerCount)
// update service
cron.AddJobAtIntervals("UpdateServices", time.Duration(opts.UpdateInterval)*time.Minute, models.NotifyService.UpdateServices)
// wrapped func to resend notifications
cron.AddJobAtIntervals("ReSendNotifications", time.Duration(opts.ReSendScope)*time.Second, models.NotificationManager.ReSend)
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
// wrapped func to resend notifications
cron.AddJobAtIntervals("ReSendNotifications", time.Duration(opts.ReSendScope)*time.Second, models.NotificationManager.ReSend)
cron.AddJobEveryFewHour("AutoPurgeSplitable", 4, 30, 0, db.AutoPurgeSplitable, false)
cron.Start()
cron.Start()
defer cron.Stop()
}
app.ServeForever(applicaion, baseOpts)
}

View File

@@ -82,9 +82,13 @@ func (t *SSplitTableSpec) getLastTableSpec(lastDate time.Time) (*sqlchemy.STable
} else {
if lastMeta.StartDate.IsZero() {
indexCol := t.tableSpec.ColumnSpec(t.indexField)
startDate := lastMeta.CreatedAt
if startDate.IsZero() {
startDate = lastDate
}
_, err = t.metaSpec.Update(lastMeta, func() error {
lastMeta.Start = indexCol.AutoIncrementOffset()
lastMeta.StartDate = lastDate
lastMeta.StartDate = startDate
return nil
})
if err != nil {
@@ -107,12 +111,20 @@ func (t *SSplitTableSpec) getLastTableSpec(lastDate time.Time) (*sqlchemy.STable
func (t *SSplitTableSpec) Insert(dt interface{}) error {
var lastDate time.Time
vs := reflectutils.FetchAllStructFieldValueSet(reflect.Indirect(reflect.ValueOf(dt)))
dataValue := reflect.Indirect(reflect.ValueOf(dt))
vs := reflectutils.FetchAllStructFieldValueSet(dataValue)
if lastDateV, ok := vs.GetValue(t.dateField); !ok {
return errors.Wrap(errors.ErrInvalidStatus, "no dateField found")
} else {
lastDate = lastDateV.Interface().(time.Time)
}
if lastDate.IsZero() {
lastDate = time.Now()
succ := reflectutils.SetStructFieldValue(dataValue, t.dateField, reflect.ValueOf(lastDate))
if !succ {
return errors.Wrap(errors.ErrInvalidStatus, "set dateField failed")
}
}
lastTableSpec, err := t.getLastTableSpecWithLock(lastDate)
if err != nil {
return errors.Wrap(err, "getLastTableSpec")