Show last cron messages on monitor page (#19223)

As discussed on #19221 we should store the results of the last task message on the
crontask and show them on the monitor page.

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
zeripath 2022-03-29 02:31:07 +01:00 committed by GitHub
parent e69b7a92ed
commit 90e0a402c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 67 deletions

View file

@ -7,8 +7,6 @@ package cron
import (
"time"
user_model "code.gitea.io/gitea/models/user"
"github.com/unknwon/i18n"
)
@ -17,7 +15,7 @@ type Config interface {
IsEnabled() bool
DoRunAtStart() bool
GetSchedule() string
FormatMessage(name, status string, doer *user_model.User, args ...interface{}) string
FormatMessage(locale, name, status, doer string, args ...interface{}) string
DoNoticeOnSuccess() bool
}
@ -70,19 +68,20 @@ func (b *BaseConfig) DoNoticeOnSuccess() bool {
}
// FormatMessage returns a message for the task
func (b *BaseConfig) FormatMessage(name, status string, doer *user_model.User, args ...interface{}) string {
// 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, name, status, doer string, args ...interface{}) string {
realArgs := make([]interface{}, 0, len(args)+2)
realArgs = append(realArgs, i18n.Tr("en-US", "admin.dashboard."+name))
if doer == nil {
realArgs = append(realArgs, i18n.Tr(locale, "admin.dashboard."+name))
if doer == "" {
realArgs = append(realArgs, "(Cron)")
} else {
realArgs = append(realArgs, doer.Name)
realArgs = append(realArgs, doer)
}
if len(args) > 0 {
realArgs = append(realArgs, args...)
}
if doer == nil || (doer.ID == -1 && doer.Name == "(Cron)") {
return i18n.Tr("en-US", "admin.dashboard.cron."+status, realArgs...)
if doer == "" {
return i18n.Tr(locale, "admin.dashboard.cron."+status, realArgs...)
}
return i18n.Tr("en-US", "admin.dashboard.task."+status, realArgs...)
return i18n.Tr(locale, "admin.dashboard.task."+status, realArgs...)
}