mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 20:27:03 +01:00
Merge pull request '[GITEA] Actually recover from a panic in cron task' (#1912) from forgejo-bp-1911 into v1.21/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1912
This commit is contained in:
commit
bbdb47dfa1
1 changed files with 7 additions and 5 deletions
|
@ -84,13 +84,15 @@ func (t *Task) RunWithUser(doer *user_model.User, config Config) {
|
||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
defer func() {
|
defer func() {
|
||||||
taskStatusTable.Stop(t.Name)
|
taskStatusTable.Stop(t.Name)
|
||||||
|
}()
|
||||||
|
graceful.GetManager().RunWithShutdownContext(func(baseCtx context.Context) {
|
||||||
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
// Recover a panic within the
|
// Recover a panic within the execution of the task.
|
||||||
combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2))
|
combinedErr := fmt.Errorf("%s\n%s", err, log.Stack(2))
|
||||||
log.Error("PANIC whilst running task: %s Value: %v", t.Name, combinedErr)
|
log.Error("PANIC whilst running task: %s Value: %v", t.Name, combinedErr)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
graceful.GetManager().RunWithShutdownContext(func(baseCtx context.Context) {
|
|
||||||
// Store the time of this run, before the function is executed, so it
|
// Store the time of this run, before the function is executed, so it
|
||||||
// matches the behavior of what the cron library does.
|
// matches the behavior of what the cron library does.
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
|
|
Loading…
Reference in a new issue