mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(region): add cronjob to cleaning snapshot (#17002)
Co-authored-by: 马鸿飞 <mahongfei@yunion.cn>
This commit is contained in:
@@ -1185,3 +1185,28 @@ func (manager *SSnapshotManager) ListItemExportKeys(ctx context.Context,
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SSnapshotManager) DataCleaning(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
|
||||
err := dataCleaning(manager.TableSpec().Name())
|
||||
if err != nil {
|
||||
log.Errorf("************* %s:dataCleaning error:%s ************", manager.TableSpec().Name(), err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func dataCleaning(tableName string) error {
|
||||
now := time.Now()
|
||||
monthsDaysAgo := now.AddDate(0, -1, 0).Format("2006-01-02 15:04:05")
|
||||
sqlStr := fmt.Sprintf(
|
||||
"delete from %s where deleted = 1 and updated_at < '%s'",
|
||||
tableName,
|
||||
monthsDaysAgo,
|
||||
)
|
||||
q := sqlchemy.NewRawQuery(sqlStr)
|
||||
rows, err := q.Rows()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to delete expired data in %q", tableName)
|
||||
}
|
||||
defer rows.Close()
|
||||
log.Infof("delete expired data in %q successfully", tableName)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -187,6 +187,7 @@ type ComputeOptions struct {
|
||||
|
||||
DefaultIPAllocationDirection string `help:"default IP allocation direction" default:"stepdown"`
|
||||
|
||||
CleanupSnapshots bool `help:"create a cronjob to cleaning snapshots every day" default:"true"`
|
||||
// 弹性伸缩中的ecs一般会有特殊的系统标签,通过指定这些标签可以忽略这部分ecs的同步, 指定多个key需要以 ',' 分隔
|
||||
SkipServerBySysTagKeys string `help:"skip server,disk sync and create with system tags" default:"acs:autoscaling:scalingGroupId"`
|
||||
SkipServerByUserTagKeys string `help:"skip server,disk sync and create with user tags" default:""`
|
||||
|
||||
@@ -186,6 +186,10 @@ func StartService() {
|
||||
cron.AddJobEveryFewDays("SyncElasticCacheSkus", opts.SyncSkusDay, opts.SyncSkusHour, 0, 0, models.SyncElasticCacheSkus, true)
|
||||
cron.AddJobEveryFewDays("StorageSnapshotsRecycle", 1, 2, 0, 0, models.StorageManager.StorageSnapshotsRecycle, false)
|
||||
|
||||
if options.Options.CleanupSnapshots {
|
||||
cron.AddJobEveryFewDays("SnapshotDataCleaning", 1, 0, 0, 0, models.SnapshotManager.DataCleaning, true)
|
||||
}
|
||||
|
||||
cron.AddJobAtIntervalsWithStartRun("SyncCloudImages", time.Duration(opts.CloudImagesSyncIntervalHours)*time.Hour, models.SyncPublicCloudImages, true)
|
||||
|
||||
cron.AddJobEveryFewHour("InspectAllTemplate", 1, 0, 0, models.GuestTemplateManager.InspectAllTemplate, true)
|
||||
|
||||
Reference in New Issue
Block a user