mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #9934 from rainzm/notify/receivernotification
feat(notify): clean data for receiver_notifications
This commit is contained in:
@@ -31,6 +31,7 @@ func InitDB() error {
|
||||
NotificationManager,
|
||||
ConfigManager,
|
||||
TemplateManager,
|
||||
ReceiverNotificationManager,
|
||||
} {
|
||||
err := manager.InitializeData()
|
||||
if err != nil {
|
||||
|
||||
@@ -33,7 +33,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/image/policy"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/monitor/models"
|
||||
notifyv2 "yunion.io/x/onecloud/pkg/notify"
|
||||
"yunion.io/x/onecloud/pkg/notify/oldmodels"
|
||||
"yunion.io/x/onecloud/pkg/notify/options"
|
||||
@@ -355,19 +354,23 @@ func (self *SNotificationManager) singleRowLineQuery(sqlStr string, dest ...inte
|
||||
}
|
||||
|
||||
func (self *SNotificationManager) InitializeData() error {
|
||||
return dataCleaning(self.TableSpec().Name())
|
||||
}
|
||||
|
||||
func dataCleaning(tableName string) error {
|
||||
now := time.Now()
|
||||
monthsDaysAgo := now.AddDate(0, -1, 0).Format("2006-01-02 15:04:05")
|
||||
sqlStr := fmt.Sprintf(
|
||||
"update %s set deleted = 1 where deleted = 0 and created_at < '%s'",
|
||||
models.NotificationManager.TableSpec().Name(),
|
||||
tableName,
|
||||
monthsDaysAgo,
|
||||
)
|
||||
q := sqlchemy.NewRawQuery(sqlStr)
|
||||
_, err := q.Rows()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to delete expired notification")
|
||||
return errors.Wrapf(err, "unable to delete expired data in %q", tableName)
|
||||
}
|
||||
log.Infof("delete expired notification successfully")
|
||||
log.Infof("delete expired data in %q successfully", tableName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,10 @@ type SReceiverNotification struct {
|
||||
FailedReason string `width:"1024"`
|
||||
}
|
||||
|
||||
func (self *SReceiverNotificationManager) InitializeData() error {
|
||||
return dataCleaning(self.TableSpec().Name())
|
||||
}
|
||||
|
||||
func (rnm *SReceiverNotificationManager) Create(ctx context.Context, userCred mcclient.TokenCredential, receiverID, notificationID string) (*SReceiverNotification, error) {
|
||||
rn := &SReceiverNotification{
|
||||
ReceiverID: receiverID,
|
||||
|
||||
Reference in New Issue
Block a user