Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/.vscode
**/__debug_bin*
**/.DS_Store
.agent/
70 changes: 42 additions & 28 deletions core/common/consume/consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,35 @@ func AsyncConsume(
}

consumeWaitGroup.Add(1)
defer func() {
consumeWaitGroup.Done()

if r := recover(); r != nil {
log.Errorf("panic in consume: %v", r)
}
go func() {
defer func() {
consumeWaitGroup.Done()

if r := recover(); r != nil {
log.Errorf("panic in consume: %v", r)
}
}()

Consume(
context.Background(),
time.Now(),
postGroupConsumer,
firstByteAt,
code,
meta,
usage,
usageContext,
modelPrice,
content,
ip,
retryTimes,
requestDetail,
downstreamResult,
metadata,
upstreamID,
asyncUsageStatus,
)
}()

go Consume(
context.Background(),
time.Now(),
postGroupConsumer,
firstByteAt,
code,
meta,
usage,
usageContext,
modelPrice,
content,
ip,
retryTimes,
requestDetail,
downstreamResult,
metadata,
upstreamID,
asyncUsageStatus,
)
}

func Consume(
Expand All @@ -95,6 +97,11 @@ func Consume(
return
}

groupChannel := meta != nil && meta.Channel.Scope == model.ChannelScopeGroup
if groupChannel {
asyncUsageStatus = model.AsyncUsageStatusNone
}

recordUsage := usage

amountDetail := model.Amount{}
Expand All @@ -111,8 +118,10 @@ func Consume(
}

if downstreamResult {
// TODO: add record actual consume amount
_ = consumeAmount(ctx, amountDetail.UsedAmount, postGroupConsumer, meta)
if !groupChannel {
// TODO: add record actual consume amount
_ = consumeAmount(ctx, amountDetail.UsedAmount, postGroupConsumer, meta)
}
} else if amountDetail.UsedAmount != 0 {
log.Warnf(
"not downstream result but used amount is not zero, request_id: %s, used_amount: %f",
Expand Down Expand Up @@ -151,6 +160,11 @@ func Consume(
)
if err != nil {
log.Error("error batch record consume: " + err.Error())

if groupChannel {
return
}

notify.ErrorThrottle("recordConsume", time.Minute*5, "record consume failed", err.Error())
}
}
Expand Down
Loading
Loading