@@ -3,17 +3,19 @@ package services
33import (
44 "context"
55 "github.com/TeaOSLab/EdgeAPI/internal/db/models"
6+ "github.com/TeaOSLab/EdgeAPI/internal/installers"
67 "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
78 "github.com/iwind/TeaGo/dbs"
9+ stringutil "github.com/iwind/TeaGo/utils/string"
810 "time"
911)
1012
11- // 节点同步任务相关服务
13+ // NodeTaskService 节点同步任务相关服务
1214type NodeTaskService struct {
1315 BaseService
1416}
1517
16- // 获取单节点同步任务
18+ // FindNodeTasks 获取单节点同步任务
1719func (this * NodeTaskService ) FindNodeTasks (ctx context.Context , req * pb.FindNodeTasksRequest ) (* pb.FindNodeTasksResponse , error ) {
1820 nodeId , err := this .ValidateNode (ctx )
1921 if err != nil {
@@ -36,10 +38,26 @@ func (this *NodeTaskService) FindNodeTasks(ctx context.Context, req *pb.FindNode
3638 })
3739 }
3840
41+ // 版本更新任务
42+ status , err := models .SharedNodeDAO .FindNodeStatus (tx , nodeId )
43+ if err != nil {
44+ return nil , err
45+ }
46+ if status != nil && len (status .OS ) > 0 && len (status .Arch ) > 0 && len (status .BuildVersion ) > 0 {
47+ deployFile := installers .SharedDeployManager .FindNodeFile (status .OS , status .Arch )
48+ if deployFile != nil {
49+ if stringutil .VersionCompare (deployFile .Version , status .BuildVersion ) > 0 {
50+ pbTasks = append (pbTasks , & pb.NodeTask {
51+ Type : models .NodeTaskTypeNodeVersionChanged ,
52+ })
53+ }
54+ }
55+ }
56+
3957 return & pb.FindNodeTasksResponse {NodeTasks : pbTasks }, nil
4058}
4159
42- // 报告同步任务结果
60+ // ReportNodeTaskDone 报告同步任务结果
4361func (this * NodeTaskService ) ReportNodeTaskDone (ctx context.Context , req * pb.ReportNodeTaskDoneRequest ) (* pb.RPCSuccess , error ) {
4462 _ , err := this .ValidateNode (ctx )
4563 if err != nil {
@@ -55,7 +73,7 @@ func (this *NodeTaskService) ReportNodeTaskDone(ctx context.Context, req *pb.Rep
5573 return this .Success ()
5674}
5775
58- // 获取所有正在同步的集群信息
76+ // FindNodeClusterTasks 获取所有正在同步的集群信息
5977func (this * NodeTaskService ) FindNodeClusterTasks (ctx context.Context , req * pb.FindNodeClusterTasksRequest ) (* pb.FindNodeClusterTasksResponse , error ) {
6078 _ , err := this .ValidateAdmin (ctx , 0 )
6179 if err != nil {
@@ -125,7 +143,7 @@ func (this *NodeTaskService) FindNodeClusterTasks(ctx context.Context, req *pb.F
125143 return & pb.FindNodeClusterTasksResponse {ClusterTasks : pbClusterTasks }, nil
126144}
127145
128- // 检查是否有正在执行的任务
146+ // ExistsNodeTasks 检查是否有正在执行的任务
129147func (this * NodeTaskService ) ExistsNodeTasks (ctx context.Context , req * pb.ExistsNodeTasksRequest ) (* pb.ExistsNodeTasksResponse , error ) {
130148 _ , err := this .ValidateAdmin (ctx , 0 )
131149 if err != nil {
@@ -154,7 +172,7 @@ func (this *NodeTaskService) ExistsNodeTasks(ctx context.Context, req *pb.Exists
154172 }, nil
155173}
156174
157- // 删除任务
175+ // DeleteNodeTask 删除任务
158176func (this * NodeTaskService ) DeleteNodeTask (ctx context.Context , req * pb.DeleteNodeTaskRequest ) (* pb.RPCSuccess , error ) {
159177 _ , err := this .ValidateAdmin (ctx , 0 )
160178 if err != nil {
@@ -170,7 +188,7 @@ func (this *NodeTaskService) DeleteNodeTask(ctx context.Context, req *pb.DeleteN
170188 return this .Success ()
171189}
172190
173- // 批量删除任务
191+ // DeleteNodeTasks 批量删除任务
174192func (this * NodeTaskService ) DeleteNodeTasks (ctx context.Context , req * pb.DeleteNodeTasksRequest ) (* pb.RPCSuccess , error ) {
175193 _ , err := this .ValidateAdmin (ctx , 0 )
176194 if err != nil {
@@ -188,7 +206,7 @@ func (this *NodeTaskService) DeleteNodeTasks(ctx context.Context, req *pb.Delete
188206 return this .Success ()
189207}
190208
191- // 计算正在执行的任务数量
209+ // CountDoingNodeTasks 计算正在执行的任务数量
192210func (this * NodeTaskService ) CountDoingNodeTasks (ctx context.Context , req * pb.CountDoingNodeTasksRequest ) (* pb.RPCCountResponse , error ) {
193211 _ , err := this .ValidateAdmin (ctx , 0 )
194212 if err != nil {
@@ -205,7 +223,7 @@ func (this *NodeTaskService) CountDoingNodeTasks(ctx context.Context, req *pb.Co
205223 return this .SuccessCount (count )
206224}
207225
208- // 查找需要通知的任务
226+ // FindNotifyingNodeTasks 查找需要通知的任务
209227func (this * NodeTaskService ) FindNotifyingNodeTasks (ctx context.Context , req * pb.FindNotifyingNodeTasksRequest ) (* pb.FindNotifyingNodeTasksResponse , error ) {
210228 _ , err := this .ValidateAdmin (ctx , 0 )
211229 if err != nil {
@@ -241,7 +259,7 @@ func (this *NodeTaskService) FindNotifyingNodeTasks(ctx context.Context, req *pb
241259 return & pb.FindNotifyingNodeTasksResponse {NodeTasks : pbTasks }, nil
242260}
243261
244- // 设置任务已通知
262+ // UpdateNodeTasksNotified 设置任务已通知
245263func (this * NodeTaskService ) UpdateNodeTasksNotified (ctx context.Context , req * pb.UpdateNodeTasksNotifiedRequest ) (* pb.RPCSuccess , error ) {
246264 _ , err := this .ValidateAdmin (ctx , 0 )
247265 if err != nil {
0 commit comments