feat: add task polling fail error log#3473
feat: add task polling fail error log#3473feitianbubu wants to merge 1 commit intoQuantumNous:mainfrom
Conversation
WalkthroughA new error billing log recording function is introduced that automatically logs task failures during polling when a task transitions to failure status. The function extracts failure details, computes task duration, and records structured error logs with task and channel metadata. Changes
Sequence DiagramsequenceDiagram
participant TP as Task Polling Service
participant TM as Task Model
participant BL as Billing Log System
TP->>TM: UpdateWithStatus (transition to failure)
TM-->>TP: Returns Task with TaskStatusFailure
TP->>TP: Check if status == TaskStatusFailure
alt Error Logging Enabled
TP->>TP: recordTaskPollingErrorLog(ctx, channel, task)
TP->>TP: Extract task finish time & duration
TP->>TP: Build error content from FailReason
TP->>TP: Construct metadata (task ID, channel ID, stage)
TP->>BL: RecordTaskBillingLog(error details)
BL-->>TP: Log recorded
TP->>TP: Emit info log
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@service/task_polling.go`:
- Around line 535-547: The call to model.RecordTaskBillingLog is passing
nonexistent fields UseTime and Properties on RecordTaskBillingLogParams; remove
those fields and instead include use_time and properties data into the Other map
passed to model.RecordTaskBillingLog (e.g., add keys like "use_time":
useTimeSeconds and "task_properties": task.Properties into the existing other
variable) so the struct matches RecordTaskBillingLogParams and the extra data is
preserved via Other.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 94dc1d1d-93e9-4baa-8ac6-3c67f627cd61
📒 Files selected for processing (1)
service/task_polling.go
| model.RecordTaskBillingLog(model.RecordTaskBillingLogParams{ | ||
| UserId: task.UserId, | ||
| LogType: model.LogTypeError, | ||
| Content: content, | ||
| ChannelId: task.ChannelId, | ||
| ModelName: taskModelName(task), | ||
| Quota: 0, | ||
| TokenId: task.PrivateData.TokenId, | ||
| Group: task.Group, | ||
| UseTime: useTimeSeconds, | ||
| Properties: &task.Properties, | ||
| Other: other, | ||
| }) |
There was a problem hiding this comment.
Compilation error: UseTime and Properties fields do not exist in RecordTaskBillingLogParams.
The struct RecordTaskBillingLogParams (defined in model/log.go) only has 9 fields: UserId, LogType, Content, ChannelId, ModelName, Quota, TokenId, Group, and Other. The fields UseTime and Properties passed here do not exist and will cause a build failure.
If you need to include use_time and task properties in the log, add them to the other map instead.
🐛 Proposed fix to remove invalid fields and add data to `other` map
other := map[string]interface{}{
"task_id": task.TaskID,
"channel_id": task.ChannelId,
"channel_name": channelName,
"channel_type": channelType,
"failure_stage": "task_polling",
+ "use_time": useTimeSeconds,
"admin_info": map[string]interface{}{
"use_channel": []string{fmt.Sprintf("%d", task.ChannelId)},
},
}
model.RecordTaskBillingLog(model.RecordTaskBillingLogParams{
UserId: task.UserId,
LogType: model.LogTypeError,
Content: content,
ChannelId: task.ChannelId,
ModelName: taskModelName(task),
Quota: 0,
TokenId: task.PrivateData.TokenId,
Group: task.Group,
- UseTime: useTimeSeconds,
- Properties: &task.Properties,
Other: other,
})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@service/task_polling.go` around lines 535 - 547, The call to
model.RecordTaskBillingLog is passing nonexistent fields UseTime and Properties
on RecordTaskBillingLogParams; remove those fields and instead include use_time
and properties data into the Other map passed to model.RecordTaskBillingLog
(e.g., add keys like "use_time": useTimeSeconds and "task_properties":
task.Properties into the existing other variable) so the struct matches
RecordTaskBillingLogParams and the extra data is preserved via Other.
任务轮询失败记录错误日志
Summary by CodeRabbit