mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: splitable not function due to empty datefield (#23907)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -964,16 +964,6 @@ func (rc *sConverter) action(actionValue int) notify.SAction {
|
||||
return a.(notify.SAction)
|
||||
}
|
||||
|
||||
func (self *STopic) CreateEvent(ctx context.Context, resType, action, message string) (*SEvent, error) {
|
||||
eve := &SEvent{
|
||||
Message: message,
|
||||
ResourceType: resType,
|
||||
Action: action,
|
||||
TopicId: self.Id,
|
||||
}
|
||||
return eve, EventManager.TableSpec().Insert(ctx, eve)
|
||||
}
|
||||
|
||||
func (self *STopic) GetEnabledSubscribers(domainId, projectId string) ([]SSubscriber, error) {
|
||||
q := SubscriberManager.Query().Equals("topic_id", self.Id).IsTrue("enabled")
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
|
||||
@@ -69,16 +69,19 @@ func StartService() {
|
||||
}
|
||||
}
|
||||
|
||||
cron := cronman.InitCronJobManager(true, 2, opts.TimeZone)
|
||||
// update service
|
||||
cron.AddJobAtIntervalsWithStartRun("syncReciverFromKeystone", time.Duration(opts.SyncReceiverIntervalMinutes)*time.Minute, models.ReceiverManager.SyncUserFromKeystone, true)
|
||||
if !opts.IsSlaveNode {
|
||||
cron := cronman.InitCronJobManager(true, opts.CronJobWorkerCount, opts.TimeZone)
|
||||
// update service
|
||||
cron.AddJobAtIntervalsWithStartRun("syncReciverFromKeystone", time.Duration(opts.SyncReceiverIntervalMinutes)*time.Minute, models.ReceiverManager.SyncUserFromKeystone, true)
|
||||
|
||||
// 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.AddJobEveryFewDays("InitReceiverProject", 7, 0, 0, 0, models.InitReceiverProject, true)
|
||||
// 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.AddJobEveryFewDays("InitReceiverProject", 7, 0, 0, 0, models.InitReceiverProject, true)
|
||||
|
||||
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