From 7132a3be6710b7ec75ff9d08fe9614c14ae9e605 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Tue, 9 Dec 2025 13:34:16 +0800 Subject: [PATCH] fix: splitable not function due to empty datefield (#23907) Co-authored-by: Qiu Jian --- pkg/notify/models/topic.go | 10 ---------- pkg/notify/service/service.go | 19 +++++++++++-------- pkg/util/splitable/insert.go | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/pkg/notify/models/topic.go b/pkg/notify/models/topic.go index 82bfb8ff09..b325032e14 100644 --- a/pkg/notify/models/topic.go +++ b/pkg/notify/models/topic.go @@ -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( diff --git a/pkg/notify/service/service.go b/pkg/notify/service/service.go index 9b846f4e46..314be1debf 100644 --- a/pkg/notify/service/service.go +++ b/pkg/notify/service/service.go @@ -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) } diff --git a/pkg/util/splitable/insert.go b/pkg/util/splitable/insert.go index 18bdb448fc..8f80025bc2 100644 --- a/pkg/util/splitable/insert.go +++ b/pkg/util/splitable/insert.go @@ -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")