diff options
author | Brad Albright <32200834+bhalbright@users.noreply.github.com> | 2021-01-26 15:02:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-26 22:02:42 +0100 |
commit | a598877fdf64a37b20eb1bf4372cbe798fc94486 (patch) | |
tree | 14c500acefea3a5684f4e1ecedaec1ff9d9708e5 /modules/cron | |
parent | 0f726caf97e4b682172f23fb46d3992f60ed6ed2 (diff) | |
download | gitea-a598877fdf64a37b20eb1bf4372cbe798fc94486.tar.gz gitea-a598877fdf64a37b20eb1bf4372cbe798fc94486.zip |
Cron job to cleanup hook_task table (#13080)
Close **Prune hook_task Table (#10741)**
Added a cron job to delete webhook deliveries in the hook_task table. It can be turned on/off and the schedule controlled globally via app.ini. The data can be deleted by either the age of the delivery which is the default or by deleting the all but the most recent deliveries _per webhook_.
Note: I had previously submitted pr #11416 but I closed it when I realized that I had deleted per repository instead of per webhook. Also, I decided allowing the settings to be overridden via the ui was overkill. Also this version allows the deletion by age which is probably what most people would want.
Diffstat (limited to 'modules/cron')
-rw-r--r-- | modules/cron/setting.go | 8 | ||||
-rw-r--r-- | modules/cron/tasks_basic.go | 17 |
2 files changed, 25 insertions, 0 deletions
diff --git a/modules/cron/setting.go b/modules/cron/setting.go index 5fe9ca6e14..d55e5b60ad 100644 --- a/modules/cron/setting.go +++ b/modules/cron/setting.go @@ -40,6 +40,14 @@ type UpdateExistingConfig struct { UpdateExisting bool } +// CleanupHookTaskConfig represents a cron task with settings to cleanup hook_task +type CleanupHookTaskConfig struct { + BaseConfig + CleanupType string + OlderThan time.Duration + NumberToKeep int +} + // GetSchedule returns the schedule for the base config func (b *BaseConfig) GetSchedule() string { return b.Schedule diff --git a/modules/cron/tasks_basic.go b/modules/cron/tasks_basic.go index a45704e889..391cda0f89 100644 --- a/modules/cron/tasks_basic.go +++ b/modules/cron/tasks_basic.go @@ -109,6 +109,22 @@ func registerUpdateMigrationPosterID() { }) } +func registerCleanupHookTaskTable() { + RegisterTaskFatal("cleanup_hook_task_table", &CleanupHookTaskConfig{ + BaseConfig: BaseConfig{ + Enabled: true, + RunAtStart: false, + Schedule: "@every 24h", + }, + CleanupType: "OlderThan", + OlderThan: 168 * time.Hour, + NumberToKeep: 10, + }, func(ctx context.Context, _ *models.User, config Config) error { + realConfig := config.(*CleanupHookTaskConfig) + return models.CleanupHookTaskTable(ctx, models.ToHookTaskCleanupType(realConfig.CleanupType), realConfig.OlderThan, realConfig.NumberToKeep) + }) +} + func initBasicTasks() { registerUpdateMirrorTask() registerRepoHealthCheck() @@ -119,4 +135,5 @@ func initBasicTasks() { if !setting.Repository.DisableMigrations { registerUpdateMigrationPosterID() } + registerCleanupHookTaskTable() } |