Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit bbd2588

Browse files
committed
add manual exec
1 parent e486925 commit bbd2588

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

backend/internal/node/agentHelper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func StartNewContainer(nodeId, containerName string, svc *types.Service) error {
5050
ServiceName: svc.ServiceName,
5151
ServiceId: svc.ServiceId,
5252
GroupId: svc.GroupId,
53+
ManualExec: svc.Deployment.ManualExec,
5354
ServiceMetaDocker: svc.Meta,
5455
ScheduleInfo: svc.Deployment.Schedule,
5556
}

backend/internal/node/nodeCache.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,14 @@ func GetNodeInfo(nodeId string) *types.Node {
5757

5858
return n
5959
}
60+
61+
func ClearNodeCache(nodeInfo types.NodeSimpleInfo) {
62+
63+
n, err := db.GetDataById[types.Node](db.BucketNodes, nodeInfo.NodeId)
64+
if err == nil && n != nil {
65+
nodeCache.Remove(n.NodeId)
66+
ip := n.IpAddress
67+
cache.Remove(ip)
68+
}
69+
70+
}

backend/scheduler/serviceController.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func (sc *ServiceController) HandleNodeChanged() {
8484

8585
// 机器上下线时需要通知该机器所属的Group,去检查Group中所有service的状态
8686
func (sc *ServiceController) HandleNodeStatusChanged(nodeInfo types.NodeSimpleInfo) {
87+
88+
node.ClearNodeCache(nodeInfo)
89+
8790
groups, _ := db.GroupsGetByNodeId(nodeInfo.NodeId)
8891
for _, g := range groups {
8992
for _, serviceManager := range sc.ServiceCtrls {

backend/scheduler/serviceManager.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ func (sm *ServiceManager) Reconcile() {
125125
if sm.ServiceInfo.Status == types.ServiceStatusNotReady {
126126

127127
// 如果有容器正在启动,就不再继续
128-
if sm.ServiceInfo.Deployment.Type != types.DeployTypeSchedule && sm.HasPendingContainer() {
128+
if !sm.IsRunningWithSchedule() && sm.HasPendingContainer() {
129129
slog.Info("[Service Manager] Wait pending container......", "ServiceId", sm.ServiceInfo.ServiceId)
130130
return
131131
}
132132

133133
// 如果有容器失败,就不再继续
134-
if sm.ServiceInfo.Deployment.Type != types.DeployTypeSchedule && sm.HasFailedContainer() {
134+
if !sm.IsRunningWithSchedule() && sm.HasFailedContainer() {
135135
slog.Info("[Service Manager] container failed, stop dispatch......", "ServiceId", sm.ServiceInfo.ServiceId)
136136
sm.ServiceInfo.Status = types.ServiceStatusFailed
137137
sm.ServiceInfo.Memo = types.MemoCreateContainerFailed
@@ -270,12 +270,11 @@ func (sm *ServiceManager) IsContainerAllReady() bool {
270270
version := parseVersionByContainerId(c.ContainerName)
271271
if version == sm.ServiceInfo.Version {
272272
if isContainerExited(c.State) &&
273-
(sm.ServiceInfo.Deployment.Type == types.DeployTypeSchedule ||
274-
strings.EqualFold(sm.ServiceInfo.Action, types.ServiceActionStop)) {
273+
(sm.IsRunningWithSchedule() || strings.EqualFold(sm.ServiceInfo.Action, types.ServiceActionStop)) {
275274
continue
276275
}
277276

278-
if isContainerStarting(c.State) && sm.ServiceInfo.Deployment.Type == types.DeployTypeSchedule {
277+
if isContainerStarting(c.State) && sm.IsRunningWithSchedule() {
279278
continue
280279
}
281280

@@ -321,6 +320,10 @@ func (sm *ServiceManager) HasFailedContainer() bool {
321320
return false
322321
}
323322

323+
func (sm *ServiceManager) IsRunningWithSchedule() bool {
324+
return sm.ServiceInfo.Deployment.Type == types.DeployTypeSchedule || sm.ServiceInfo.Deployment.ManualExec
325+
}
326+
324327
func (sm *ServiceManager) TryToDeleteOne() (*types.ContainerStatus, bool) {
325328

326329
nodeDeployed := make(map[string]bool)
@@ -330,10 +333,8 @@ func (sm *ServiceManager) TryToDeleteOne() (*types.ContainerStatus, bool) {
330333
if version != sm.ServiceInfo.Version {
331334
return c, true
332335
}
333-
if isContainerExited(c.State) {
334-
if sm.ServiceInfo.Deployment.Type == types.DeployTypeBackground {
335-
return c, true
336-
}
336+
if isContainerExited(c.State) && !sm.IsRunningWithSchedule() {
337+
return c, true
337338
}
338339
if isContainerWarning(c.State) || isContainerRemoved(c.State) {
339340
return c, true

backend/types/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type AgentTask struct {
5656
ServiceName string `json:"serviceName"`
5757
ServiceId string `json:"serviceId"`
5858
GroupId string `json:"groupId"`
59+
ManualExec bool `json:"manualExec"`
5960
*ServiceMetaDocker
6061
*ScheduleInfo
6162
}

0 commit comments

Comments
 (0)