Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
aa8b722a
authored
Jan 12, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add SafeGoroutine
parent
f8b72863
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletions
+19
-1
common/go-channel.go
+16
-0
model/log.go
+3
-1
No files found.
common/go-channel.go
View file @
aa8b722a
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.
...
...
model/log.go
View file @
aa8b722a
...
@@ -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
())
})
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment