summaryrefslogtreecommitdiffstats
path: root/services/cron/setting.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /services/cron/setting.go
parentInitial commit. (diff)
downloadforgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.tar.xz
forgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'services/cron/setting.go')
-rw-r--r--services/cron/setting.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/services/cron/setting.go b/services/cron/setting.go
new file mode 100644
index 0000000..6dad888
--- /dev/null
+++ b/services/cron/setting.go
@@ -0,0 +1,86 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package cron
+
+import (
+ "time"
+
+ "code.gitea.io/gitea/modules/translation"
+)
+
+// Config represents a basic configuration interface that cron task
+type Config interface {
+ IsEnabled() bool
+ DoRunAtStart() bool
+ GetSchedule() string
+ FormatMessage(locale translation.Locale, name, status, doer string, args ...any) string
+ DoNoticeOnSuccess() bool
+}
+
+// BaseConfig represents the basic config for a Cron task
+type BaseConfig struct {
+ Enabled bool
+ RunAtStart bool
+ Schedule string
+ NoticeOnSuccess bool
+}
+
+// OlderThanConfig represents a cron task with OlderThan setting
+type OlderThanConfig struct {
+ BaseConfig
+ OlderThan time.Duration
+}
+
+// UpdateExistingConfig represents a cron task with UpdateExisting setting
+type UpdateExistingConfig struct {
+ BaseConfig
+ 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
+}
+
+// IsEnabled returns the enabled status for the config
+func (b *BaseConfig) IsEnabled() bool {
+ return b.Enabled
+}
+
+// DoRunAtStart returns whether the task should be run at the start
+func (b *BaseConfig) DoRunAtStart() bool {
+ return b.RunAtStart
+}
+
+// DoNoticeOnSuccess returns whether a success notice should be posted
+func (b *BaseConfig) DoNoticeOnSuccess() bool {
+ return b.NoticeOnSuccess
+}
+
+// FormatMessage returns a message for the task
+// Please note the `status` string will be concatenated with `admin.dashboard.cron.` and `admin.dashboard.task.` to provide locale messages. Similarly `name` will be composed with `admin.dashboard.` to provide the locale name for the task.
+func (b *BaseConfig) FormatMessage(locale translation.Locale, name, status, doer string, args ...any) string {
+ realArgs := make([]any, 0, len(args)+2)
+ realArgs = append(realArgs, locale.TrString("admin.dashboard."+name))
+ if doer == "" {
+ realArgs = append(realArgs, "(Cron)")
+ } else {
+ realArgs = append(realArgs, doer)
+ }
+ if len(args) > 0 {
+ realArgs = append(realArgs, args...)
+ }
+ if doer == "" {
+ return locale.TrString("admin.dashboard.cron."+status, realArgs...)
+ }
+ return locale.TrString("admin.dashboard.task."+status, realArgs...)
+}