diff --git a/internal/web/actions/default/clusters/tasks/check.go b/internal/web/actions/default/clusters/tasks/check.go index f27e4f6a..8f032de3 100644 --- a/internal/web/actions/default/clusters/tasks/check.go +++ b/internal/web/actions/default/clusters/tasks/check.go @@ -3,23 +3,38 @@ package tasks import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "time" ) type CheckAction struct { actionutils.ParentAction } -func (this *CheckAction) RunPost(params struct{}) { - resp, err := this.RPC().NodeTaskRPC().ExistsNodeTasks(this.AdminContext(), &pb.ExistsNodeTasksRequest{ - ExcludeTypes: []string{"ipItemChanged"}, - }) - if err != nil { - this.ErrorPage(err) - return - } +func (this *CheckAction) RunPost(params struct { + IsDoing bool + HasError bool + IsUpdated bool +}) { + var maxTries = 10 + for i := 0; i < maxTries; i++ { + resp, err := this.RPC().NodeTaskRPC().ExistsNodeTasks(this.AdminContext(), &pb.ExistsNodeTasksRequest{ + ExcludeTypes: []string{"ipItemChanged"}, + }) + if err != nil { + this.ErrorPage(err) + return + } - this.Data["isDoing"] = resp.ExistTasks - this.Data["hasError"] = resp.ExistError + // 如果没有数据变化,继续查询 + if i < maxTries-1 && params.IsUpdated && resp.ExistTasks == params.IsDoing && resp.ExistError == params.HasError { + time.Sleep(3 * time.Second) + continue + } + + this.Data["isDoing"] = resp.ExistTasks + this.Data["hasError"] = resp.ExistError + break + } this.Success() } diff --git a/internal/web/actions/default/dns/tasks/check.go b/internal/web/actions/default/dns/tasks/check.go index 0fcbd0c2..843866a7 100644 --- a/internal/web/actions/default/dns/tasks/check.go +++ b/internal/web/actions/default/dns/tasks/check.go @@ -3,21 +3,36 @@ package tasks import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "time" ) type CheckAction struct { actionutils.ParentAction } -func (this *CheckAction) RunPost(params struct{}) { - resp, err := this.RPC().DNSTaskRPC().ExistsDNSTasks(this.AdminContext(), &pb.ExistsDNSTasksRequest{}) - if err != nil { - this.ErrorPage(err) - return - } +func (this *CheckAction) RunPost(params struct { + IsDoing bool + HasError bool + IsUpdated bool +}) { + var maxTries = 10 + for i := 0; i < maxTries; i++ { + resp, err := this.RPC().DNSTaskRPC().ExistsDNSTasks(this.AdminContext(), &pb.ExistsDNSTasksRequest{}) + if err != nil { + this.ErrorPage(err) + return + } - this.Data["isDoing"] = resp.ExistTasks - this.Data["hasError"] = resp.ExistError + // 如果没有数据变化,继续查询 + if i < maxTries-1 && params.IsUpdated && resp.ExistTasks == params.IsDoing && resp.ExistError == params.HasError { + time.Sleep(3 * time.Second) + continue + } + + this.Data["isDoing"] = resp.ExistTasks + this.Data["hasError"] = resp.ExistError + break + } this.Success() } diff --git a/web/views/@default/@layout.js b/web/views/@default/@layout.js index ffd54c72..f00dc5f3 100644 --- a/web/views/@default/@layout.js +++ b/web/views/@default/@layout.js @@ -118,6 +118,12 @@ Tea.context(function () { return } this.$post("/clusters/tasks/check") + .params({ + isDoing: this.doingNodeTasks.isDoing ? 1 : 0, + hasError: this.doingNodeTasks.hasError ? 1 : 0, + isUpdated: this.doingNodeTasks.isUpdated ? 1 : 0 + }) + .timeout(60) .success(function (resp) { this.doingNodeTasks.isDoing = resp.data.isDoing this.doingNodeTasks.hasError = resp.data.hasError @@ -151,6 +157,12 @@ Tea.context(function () { return } this.$post("/dns/tasks/check") + .params({ + isDoing: this.doingDNSTasks.isDoing ? 1 : 0, + hasError: this.doingDNSTasks.hasError ? 1 : 0, + isUpdated: this.doingDNSTasks.isUpdated ? 1 : 0 + }) + .timeout(60) .success(function (resp) { this.doingDNSTasks.isDoing = resp.data.isDoing this.doingDNSTasks.hasError = resp.data.hasError