From 2c41ac8290ecbda4f615b3936ba03f5c96e77418 Mon Sep 17 00:00:00 2001 From: luowei Date: Thu, 20 Jun 2024 15:39:56 +0800 Subject: [PATCH] Reduce code duplication --- sqle/server/auditplan/task.go | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/sqle/server/auditplan/task.go b/sqle/server/auditplan/task.go index 132816207b..92fcdf8396 100644 --- a/sqle/server/auditplan/task.go +++ b/sqle/server/auditplan/task.go @@ -262,23 +262,9 @@ func NewDefaultTask(entry *logrus.Entry, ap *model.AuditPlan) Task { } func (at *DefaultTask) Audit() (*AuditResultResp, error) { - var task *model.Task - if at.ap.InstanceName == "" { - task = &model.Task{ - DBType: at.ap.DBType, - } - } else { - ctx, cancel := context.WithTimeout(context.Background(), time.Second*20) - defer cancel() - instance, _, err := dms.GetInstanceInProjectByName(ctx, string(at.ap.ProjectId), at.ap.InstanceName) - if err != nil { - return nil, err - } - task = &model.Task{ - Instance: instance, - Schema: at.ap.InstanceDatabase, - DBType: at.ap.DBType, - } + task, err := getTaskWithInstanceByAuditPlan(at.ap, at.persist) + if err != nil { + return nil, err } return at.baseTask.audit(task) }