refactor(task): 优化任务处理中的余额检查逻辑
This commit is contained in:
@@ -38,21 +38,19 @@ func (w *asyncWorker) handleOne(ctx context.Context, task *entity.ModelGatewayTa
|
|||||||
rawData []byte
|
rawData []byte
|
||||||
result map[string]any
|
result map[string]any
|
||||||
err error
|
err error
|
||||||
|
surplus float64
|
||||||
)
|
)
|
||||||
g.Log().Infof(ctx, "[handleOne] 开始 taskId=%s model=%s", task.TaskID, task.ModelName)
|
g.Log().Infof(ctx, "[handleOne] 开始 taskId=%s model=%s", task.TaskID, task.ModelName)
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// 1) 查询余额
|
// 1) 查询余额
|
||||||
// ============================================
|
// ============================================
|
||||||
var surplus float64
|
surplus, _ = gateway.GetTenantSurplus(ctx, task.TenantId)
|
||||||
if len(model.BillingConfig) > 0 {
|
if surplus <= 0 {
|
||||||
surplus, _ = gateway.GetTenantSurplus(ctx, task.TenantId)
|
w.failTask(ctx, task, startTime, "租户余额不足")
|
||||||
if surplus <= 0 {
|
return
|
||||||
w.failTask(ctx, task, startTime, "租户余额不足")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
g.Log().Infof(ctx, "[handleOne] 当前余额 tenantId=%d surplus=%.2f", task.TenantId, surplus)
|
|
||||||
}
|
}
|
||||||
|
g.Log().Infof(ctx, "[handleOne] 当前余额 tenantId=%d surplus=%.2f", task.TenantId, surplus)
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// 2) 调用模型
|
// 2) 调用模型
|
||||||
|
|||||||
Reference in New Issue
Block a user