Skip to content

Commit 48598a7

Browse files
authored
Mirror System Notice reports are too frequent (go-gitea#12438)
This PR switches off the success reports from the Update Mirrors cron job as they are too frequent and not necessarily helpful. Signed-off-by: Andrew Thornton <[email protected]>
1 parent 42a31c7 commit 48598a7

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

modules/cron/setting.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ type Config interface {
1717
DoRunAtStart() bool
1818
GetSchedule() string
1919
FormatMessage(name, status string, doer *models.User, args ...interface{}) string
20+
DoNoticeOnSuccess() bool
2021
}
2122

2223
// BaseConfig represents the basic config for a Cron task
2324
type BaseConfig struct {
24-
Enabled bool
25-
RunAtStart bool
26-
Schedule string
25+
Enabled bool
26+
RunAtStart bool
27+
Schedule string
28+
NoSuccessNotice bool
2729
}
2830

2931
// OlderThanConfig represents a cron task with OlderThan setting
@@ -53,6 +55,11 @@ func (b *BaseConfig) DoRunAtStart() bool {
5355
return b.RunAtStart
5456
}
5557

58+
// DoNoticeOnSuccess returns whether a success notice should be posted
59+
func (b *BaseConfig) DoNoticeOnSuccess() bool {
60+
return !b.NoSuccessNotice
61+
}
62+
5663
// FormatMessage returns a message for the task
5764
func (b *BaseConfig) FormatMessage(name, status string, doer *models.User, args ...interface{}) string {
5865
realArgs := make([]interface{}, 0, len(args)+2)

modules/cron/tasks.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ func (t *Task) RunWithUser(doer *models.User, config Config) {
9898
}
9999
return
100100
}
101-
if err := models.CreateNotice(models.NoticeTask, config.FormatMessage(t.Name, "finished", doer)); err != nil {
102-
log.Error("CreateNotice: %v", err)
101+
if config.DoNoticeOnSuccess() {
102+
if err := models.CreateNotice(models.NoticeTask, config.FormatMessage(t.Name, "finished", doer)); err != nil {
103+
log.Error("CreateNotice: %v", err)
104+
}
103105
}
104106
})
105107
}

modules/cron/tasks_basic.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616

1717
func registerUpdateMirrorTask() {
1818
RegisterTaskFatal("update_mirrors", &BaseConfig{
19-
Enabled: true,
20-
RunAtStart: false,
21-
Schedule: "@every 10m",
19+
Enabled: true,
20+
RunAtStart: false,
21+
Schedule: "@every 10m",
22+
NoSuccessNotice: true,
2223
}, func(ctx context.Context, _ *models.User, _ Config) error {
2324
return mirror_service.Update(ctx)
2425
})

0 commit comments

Comments
 (0)