mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix: splitable not function due to empty datefield (#23913)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user