@@ -136,8 +136,14 @@ func (s *Scheduler) runTask(task config.ScheduledTaskConfig) {
136136 clientCfg := s .clientCfg
137137 s .mu .Unlock ()
138138
139- log .Printf ("[Scheduler] 开始执行任务: %q employee=%q webhook=%s product=%q project=%q workspace=%q region=%q" ,
140- task .Name , task .EmployeeName , task .Webhook .Type , task .Product , task .Project , task .Workspace , task .Region )
139+ log .Printf ("[Scheduler] ========== 任务触发 ==========" )
140+ log .Printf ("[Scheduler] 任务名称: %q" , task .Name )
141+ log .Printf ("[Scheduler] Cron 表达式: %q" , task .Cron )
142+ log .Printf ("[Scheduler] 数字员工: %q" , task .EmployeeName )
143+ log .Printf ("[Scheduler] Webhook: type=%s url=%s" , task .Webhook .Type , maskURL (task .Webhook .URL ))
144+ log .Printf ("[Scheduler] 产品配置: product=%q project=%q workspace=%q region=%q" ,
145+ task .Product , task .Project , task .Workspace , task .Region )
146+
141147 prompt := task .Prompt
142148 if task .ConciseReply {
143149 prompt += "\n \n 简化最终输出 适合聊天工具上阅读"
@@ -159,28 +165,30 @@ func (s *Scheduler) runTask(task config.ScheduledTaskConfig) {
159165 taskWorkspace := task .Workspace
160166 taskRegion := task .Region
161167
168+ log .Printf ("[Scheduler] 任务 %q 开始查询数字员工..." , task .Name )
162169 reply , err := queryEmployee (clientCfg , task .Name , task .EmployeeName , prompt , s .timezone , taskProduct , taskProject , taskWorkspace , taskRegion )
163170 if err != nil {
164171 log .Printf ("[Scheduler] 任务 %q 查询数字员工失败: %v" , task .Name , err )
165172 return
166173 }
167174
168- log .Printf ("[Scheduler] 任务 %q 数字员工原始响应(%d 字): %s" ,
169- task .Name , len ([]rune (reply )), reply )
175+ log .Printf ("[Scheduler] 任务 %q 数字员工响应完成(%d 字)" , task .Name , len ([]rune (reply )))
170176
171177 if reply == "" {
172178 log .Printf ("[Scheduler] 任务 %q 数字员工返回空响应,跳过发送" , task .Name )
173179 return
174180 }
175181
182+ log .Printf ("[Scheduler] 任务 %q 开始发送 Webhook (type=%s)..." , task .Name , task .Webhook .Type )
176183 raw , err := sendToWebhook (task .Webhook , reply )
177184 if err != nil {
178185 log .Printf ("[Scheduler] 任务 %q 发送 webhook 失败: %v(平台响应: %s)" , task .Name , err , raw )
179186 return
180187 }
181188
182189 elapsed := time .Since (startTime ).Round (time .Millisecond )
183- log .Printf ("[Scheduler] 任务 %q 执行完成,耗时 %s,webhook 平台响应: %s" , task .Name , elapsed , raw )
190+ log .Printf ("[Scheduler] 任务 %q 执行完成,耗时 %s" , task .Name , elapsed )
191+ log .Printf ("[Scheduler] ========== 任务结束 ==========" )
184192}
185193
186194// QueryEmployee 向数字员工发送消息,等待完整响应并返回文本(公开,供外部触发测试使用)
@@ -195,29 +203,37 @@ func QueryEmployeeWithVariables(clientCfg *config.ClientConfig, employeeName, me
195203
196204// queryEmployee 向数字员工发送消息,等待完整响应并返回文本
197205func queryEmployee (clientCfg * config.ClientConfig , taskName , employeeName , message string , loc * time.Location , product , project , workspace , region string ) (string , error ) {
206+ log .Printf ("[Scheduler] queryEmployee 开始: task=%q employee=%q" , taskName , employeeName )
207+
198208 sopClient , err := client .NewCMSClient (& client.Config {
199209 AccessKeyId : clientCfg .AccessKeyId ,
200210 AccessKeySecret : clientCfg .AccessKeySecret ,
201211 Endpoint : clientCfg .Endpoint ,
202212 })
203213 if err != nil {
214+ log .Printf ("[Scheduler] queryEmployee 创建 CMS 客户端失败: %v" , err )
204215 return "" , fmt .Errorf ("创建 CMS 客户端失败: %w" , err )
205216 }
217+ log .Printf ("[Scheduler] queryEmployee CMS 客户端创建成功" )
206218 cms := sopClient .CmsClient
207219
208220 // CMS API 要求必须传有效 ThreadId,先创建一次性线程
209221 threadTitle := fmt .Sprintf ("[定时任务] %s @ %s" , taskName , time .Now ().In (loc ).Format ("2006-01-02 15:04:05" ))
222+ log .Printf ("[Scheduler] queryEmployee 创建线程: %s" , threadTitle )
210223 threadResp , err := sopClient .CreateThread (& sopchat.ThreadConfig {
211224 EmployeeName : employeeName ,
212225 Title : threadTitle ,
213226 })
214227 if err != nil {
228+ log .Printf ("[Scheduler] queryEmployee 创建线程失败: %v" , err )
215229 return "" , fmt .Errorf ("创建线程失败: %w" , err )
216230 }
217231 if threadResp .Body == nil || threadResp .Body .ThreadId == nil || * threadResp .Body .ThreadId == "" {
232+ log .Printf ("[Scheduler] queryEmployee CreateThread 返回了空的 ThreadId" )
218233 return "" , fmt .Errorf ("CreateThread 返回了空的 ThreadId" )
219234 }
220235 threadId := * threadResp .Body .ThreadId
236+ log .Printf ("[Scheduler] queryEmployee 线程创建成功: threadId=%s" , threadId )
221237 nowTS := time .Now ().Unix ()
222238 variables := map [string ]interface {}{
223239 "timeStamp" : fmt .Sprintf ("%d" , nowTS ),
@@ -265,9 +281,11 @@ func queryEmployee(clientCfg *config.ClientConfig, taskName, employeeName, messa
265281
266282 startSSE := time .Now ()
267283
268- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Minute )
284+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Minute )
269285 defer cancel ()
270286
287+ log .Printf ("[Scheduler] queryEmployee 开始 SSE 流式请求: employee=%q threadId=%s timeout=30m" , employeeName , threadId )
288+
271289 responseChan := make (chan * cmsclient.CreateChatResponse )
272290 errorChan := make (chan error )
273291
@@ -276,6 +294,7 @@ func queryEmployee(clientCfg *config.ClientConfig, taskName, employeeName, messa
276294
277295 var textParts []string
278296 responseCount , msgCount := 0 , 0
297+ lastProgressLog := time .Now ()
279298
280299 for {
281300 select {
@@ -286,12 +305,19 @@ func queryEmployee(clientCfg *config.ClientConfig, taskName, employeeName, messa
286305 case response , ok := <- responseChan :
287306 if ! ok {
288307 result := strings .Join (textParts , "" )
289- log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s prompt=%q 耗时 %s 共 %d 帧 文本 %d 字" ,
290- employeeName , threadId , message , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
308+ log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s 耗时 %s 共 %d 帧 文本 %d 字" ,
309+ employeeName , threadId , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
291310 return result , nil
292311 }
293312 responseCount ++
294313
314+ // 每 30 秒打印一次进度
315+ if time .Since (lastProgressLog ) > 30 * time .Second {
316+ log .Printf ("[Scheduler] queryEmployee 进行中: employee=%q 已收 %d 帧 %d 消息 耗时 %s" ,
317+ employeeName , responseCount , msgCount , time .Since (startSSE ).Round (time .Second ))
318+ lastProgressLog = time .Now ()
319+ }
320+
295321 if response .StatusCode != nil && * response .StatusCode != 200 {
296322 log .Printf ("[Scheduler] queryEmployee 响应状态码异常: %d" , * response .StatusCode )
297323 }
@@ -302,8 +328,8 @@ func queryEmployee(clientCfg *config.ClientConfig, taskName, employeeName, messa
302328 // 检测 done 消息
303329 if sopchat .IsDoneMessage (response .Body ) {
304330 result := strings .Join (textParts , "" )
305- log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s prompt=%q 耗时 %s 共 %d 帧 文本 %d 字" ,
306- employeeName , threadId , message , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
331+ log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s 耗时 %s 共 %d 帧 文本 %d 字" ,
332+ employeeName , threadId , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
307333 return result , nil
308334 }
309335
@@ -329,18 +355,27 @@ func queryEmployee(clientCfg *config.ClientConfig, taskName, employeeName, messa
329355 case err , ok := <- errorChan :
330356 if ! ok {
331357 result := strings .Join (textParts , "" )
332- log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s prompt=%q 耗时 %s 共 %d 帧 文本 %d 字" ,
333- employeeName , threadId , message , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
358+ log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s 耗时 %s 共 %d 帧 文本 %d 字" ,
359+ employeeName , threadId , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
334360 return result , nil
335361 }
336362 if err != nil {
337- log .Printf ("[Scheduler] queryEmployee SSE error : %v" , err )
363+ log .Printf ("[Scheduler] queryEmployee SSE 错误 : %v" , err )
338364 return strings .Join (textParts , "" ), err
339365 }
340366 result := strings .Join (textParts , "" )
341- log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s prompt=%q 耗时 %s 共 %d 帧 文本 %d 字" ,
342- employeeName , threadId , message , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
367+ log .Printf ("[Scheduler] queryEmployee 完成: employee=%q threadId=%s 耗时 %s 共 %d 帧 文本 %d 字" ,
368+ employeeName , threadId , time .Since (startSSE ).Round (time .Millisecond ), responseCount , len ([]rune (result )))
343369 return result , nil
344370 }
345371 }
346372}
373+
374+ // maskURL 遮蔽 URL 中的敏感信息,只显示域名和路径的前后部分
375+ func maskURL (url string ) string {
376+ if len (url ) < 30 {
377+ return url
378+ }
379+ // 保留前 20 个字符和后 10 个字符
380+ return url [:20 ] + "..." + url [len (url )- 10 :]
381+ }
0 commit comments