@@ -228,17 +228,8 @@ func (at *TaskWrapper) stopCollect() error {
228
228
229
229
func (at * TaskWrapper ) extractSQL () {
230
230
var err error
231
- defer func () {
232
- status := model .LastCollectionNormal
233
- if err != nil {
234
- at .logger .Error (sqleErr .NewAuditPlanExecuteExtractErr (err , at .ap .InstanceID , at .ap .Type ))
235
- status = model .LastCollectionAbnormal
236
- }
237
- updateErr := at .persist .UpdateAuditPlanInfoByAPID (at .ap .ID , map [string ]interface {}{"last_collection_status" : status })
238
- if updateErr != nil {
239
- at .logger .Errorf ("update audit plan task info collection status status failed, error : %v" , updateErr )
240
- }
241
- }()
231
+ defer ProcessAuditPlanStatusAndLogError (at .logger , at .ap .ID , at .ap .InstanceID , at .ap .Type , & err )
232
+
242
233
collectionTime := time .Now ()
243
234
sqls , err := at .collect .ExtractSQL (at .logger , at .ap , at .persist )
244
235
if err != nil {
@@ -266,6 +257,19 @@ func (at *TaskWrapper) extractSQL() {
266
257
}
267
258
}
268
259
260
+ func ProcessAuditPlanStatusAndLogError (l * logrus.Entry , auditPlanId uint , instanceID , auditPlnType string , err * error ) {
261
+ s := model .GetStorage ()
262
+ status := model .LastCollectionNormal
263
+ if err != nil {
264
+ l .Error (sqleErr .NewAuditPlanExecuteExtractErr (* err , instanceID , auditPlnType ))
265
+ status = model .LastCollectionAbnormal
266
+ }
267
+ updateErr := s .UpdateAuditPlanInfoByAPID (auditPlanId , map [string ]interface {}{"last_collection_status" : status })
268
+ if updateErr != nil {
269
+ l .Errorf ("update audit plan task info collection status status failed, error : %v" , updateErr )
270
+ }
271
+ }
272
+
269
273
func (at * TaskWrapper ) loop (cancel chan struct {}, interval time.Duration ) {
270
274
if interval == 0 {
271
275
at .logger .Warnf ("task(%v) loop interval can not be zero" , at .ap .Name )
0 commit comments