2022-04-25 20:58:08 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2022-07-18 19:21:57 +02:00
|
|
|
package boards
|
2022-04-25 20:58:08 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ErrInsufficientLicense = errors.New("appropriate license required")
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
func (b *BoardsApp) RunDataRetention(nowTime, batchSize int64) (int64, error) {
|
|
|
|
b.logger.Debug("Boards RunDataRetention")
|
|
|
|
license := b.server.Store().GetLicense()
|
2022-04-25 20:58:08 +02:00
|
|
|
if license == nil || !(*license.Features.DataRetention) {
|
|
|
|
return 0, ErrInsufficientLicense
|
|
|
|
}
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
if b.server.Config().EnableDataRetention {
|
|
|
|
boardsRetentionDays := b.server.Config().DataRetentionDays
|
2022-04-25 20:58:08 +02:00
|
|
|
endTimeBoards := convertDaysToCutoff(boardsRetentionDays, time.Unix(nowTime/1000, 0))
|
2022-07-18 19:21:57 +02:00
|
|
|
return b.server.Store().RunDataRetention(endTimeBoards, batchSize)
|
2022-04-25 20:58:08 +02:00
|
|
|
}
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertDaysToCutoff(days int, now time.Time) int64 {
|
|
|
|
upToStartOfDay := now.AddDate(0, 0, -days)
|
|
|
|
cutoffDate := time.Date(upToStartOfDay.Year(), upToStartOfDay.Month(), upToStartOfDay.Day(), 0, 0, 0, 0, time.Local)
|
|
|
|
return cutoffDate.UnixNano() / int64(time.Millisecond)
|
|
|
|
}
|