Commit aa8b722a by CaIon

chore: add SafeGoroutine

parent f8b72863
package common package common
import (
"fmt"
"runtime/debug"
)
func SafeGoroutine(f func()) {
go func() {
defer func() {
if r := recover(); r != nil {
SysError(fmt.Sprintf("child goroutine panic occured: error: %v, stack: %s", r, string(debug.Stack())))
}
}()
f()
}()
}
func SafeSend(ch chan bool, value bool) (closed bool) { func SafeSend(ch chan bool, value bool) (closed bool) {
defer func() { defer func() {
// Recover from panic if one occured. A panic would mean the channel was closed. // Recover from panic if one occured. A panic would mean the channel was closed.
......
...@@ -80,7 +80,9 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke ...@@ -80,7 +80,9 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke
common.LogError(ctx, "failed to record log: "+err.Error()) common.LogError(ctx, "failed to record log: "+err.Error())
} }
if common.DataExportEnabled { if common.DataExportEnabled {
go LogQuotaData(userId, username, modelName, quota, common.GetTimestamp()) common.SafeGoroutine(func() {
LogQuotaData(userId, username, modelName, quota, common.GetTimestamp())
})
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment