forked from gitea/gitea
New cron task: delete old system notices (#19219)
Add a new cron task which deletes the old system notices.
This commit is contained in:
parent
6526733a58
commit
893c8938fc
|
@ -2018,6 +2018,19 @@ PATH =
|
||||||
;SCHEDULE = @every 168h
|
;SCHEDULE = @every 168h
|
||||||
;HTTP_ENDPOINT = https://dl.gitea.io/gitea/version.json
|
;HTTP_ENDPOINT = https://dl.gitea.io/gitea/version.json
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Delete all old system notices from database
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;[cron.delete_old_system_notices]
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;ENABLED = false
|
||||||
|
;RUN_AT_START = false
|
||||||
|
;NO_SUCCESS_NOTICE = false
|
||||||
|
;SCHEDULE = @every 168h
|
||||||
|
;OLDER_THAN = 8760h
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Git Operation timeout in seconds
|
;; Git Operation timeout in seconds
|
||||||
|
|
|
@ -921,6 +921,13 @@ Default templates for project boards:
|
||||||
- `SCHEDULE`: **@every 168h**: Cron syntax for scheduling a work, e.g. `@every 168h`.
|
- `SCHEDULE`: **@every 168h**: Cron syntax for scheduling a work, e.g. `@every 168h`.
|
||||||
- `HTTP_ENDPOINT`: **https://dl.gitea.io/gitea/version.json**: the endpoint that Gitea will check for newer versions
|
- `HTTP_ENDPOINT`: **https://dl.gitea.io/gitea/version.json**: the endpoint that Gitea will check for newer versions
|
||||||
|
|
||||||
|
#### Cron - Delete all old system notices from database ('cron.delete_old_system_notices')
|
||||||
|
- `ENABLED`: **false**: Enable service.
|
||||||
|
- `RUN_AT_START`: **false**: Run tasks at start up time (if ENABLED).
|
||||||
|
- `NO_SUCCESS_NOTICE`: **false**: Set to true to switch off success notices.
|
||||||
|
- `SCHEDULE`: **@every 168h**: Cron syntax to set how often to check.
|
||||||
|
- `OLDER_THAN`: **@every 8760h**: any system notice older than this expression will be deleted from database.
|
||||||
|
|
||||||
## Git (`git`)
|
## Git (`git`)
|
||||||
|
|
||||||
- `PATH`: **""**: The path of Git executable. If empty, Gitea searches through the PATH environment.
|
- `PATH`: **""**: The path of Git executable. If empty, Gitea searches through the PATH environment.
|
||||||
|
|
|
@ -7,6 +7,7 @@ package admin
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
@ -133,3 +134,13 @@ func DeleteNoticesByIDs(ids []int64) error {
|
||||||
Delete(new(Notice))
|
Delete(new(Notice))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteOldSystemNotices deletes all old system notices from database.
|
||||||
|
func DeleteOldSystemNotices(olderThan time.Duration) (err error) {
|
||||||
|
if olderThan <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.GetEngine(db.DefaultContext).Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Notice{})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -2463,6 +2463,7 @@ dashboard.gc_times = GC Times
|
||||||
dashboard.delete_old_actions = Delete all old actions from database
|
dashboard.delete_old_actions = Delete all old actions from database
|
||||||
dashboard.delete_old_actions.started = Delete all old actions from database started.
|
dashboard.delete_old_actions.started = Delete all old actions from database started.
|
||||||
dashboard.update_checker = Update checker
|
dashboard.update_checker = Update checker
|
||||||
|
dashboard.delete_old_system_notices = Delete all old system notices from database
|
||||||
|
|
||||||
users.user_manage_panel = User Account Management
|
users.user_manage_panel = User Account Management
|
||||||
users.new_account = Create User Account
|
users.new_account = Create User Account
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/admin"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
@ -154,6 +155,20 @@ func registerUpdateGiteaChecker() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerDeleteOldSystemNotices() {
|
||||||
|
RegisterTaskFatal("delete_old_system_notices", &OlderThanConfig{
|
||||||
|
BaseConfig: BaseConfig{
|
||||||
|
Enabled: false,
|
||||||
|
RunAtStart: false,
|
||||||
|
Schedule: "@every 168h",
|
||||||
|
},
|
||||||
|
OlderThan: 365 * 24 * time.Hour,
|
||||||
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
||||||
|
olderThanConfig := config.(*OlderThanConfig)
|
||||||
|
return admin.DeleteOldSystemNotices(olderThanConfig.OlderThan)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func initExtendedTasks() {
|
func initExtendedTasks() {
|
||||||
registerDeleteInactiveUsers()
|
registerDeleteInactiveUsers()
|
||||||
registerDeleteRepositoryArchives()
|
registerDeleteRepositoryArchives()
|
||||||
|
@ -166,4 +181,5 @@ func initExtendedTasks() {
|
||||||
registerRemoveRandomAvatars()
|
registerRemoveRandomAvatars()
|
||||||
registerDeleteOldActions()
|
registerDeleteOldActions()
|
||||||
registerUpdateGiteaChecker()
|
registerUpdateGiteaChecker()
|
||||||
|
registerDeleteOldSystemNotices()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue