MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / synAppInstall

Function synAppInstall

agent/app/service/app_utils.go:1524–1593  ·  view source on GitHub ↗
(containers map[string]container.Summary, appInstall *model.AppInstall, force bool)

Source from the content-addressed store, hash-verified

1522}
1523
1524func synAppInstall(containers map[string]container.Summary, appInstall *model.AppInstall, force bool) {
1525 oldStatus := appInstall.Status
1526 containerNames := strings.Split(appInstall.ContainerName, ",")
1527 if len(containers) == 0 {
1528 if appInstall.Status == constant.StatusUpErr && !force {
1529 return
1530 }
1531 appInstall.Status = constant.StatusError
1532 appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(containerNames, ",")).Error()
1533 _ = appInstallRepo.Save(context.Background(), appInstall)
1534 return
1535 }
1536 notFoundNames := make([]string, 0)
1537 exitNames := make([]string, 0)
1538 exitedCount := 0
1539 pausedCount := 0
1540 runningCount := 0
1541 restartingCount := 0
1542 total := len(containerNames)
1543 for _, name := range containerNames {
1544 if con, ok := containers["/"+name]; ok {
1545 switch con.State {
1546 case "exited":
1547 exitedCount++
1548 exitNames = append(exitNames, name)
1549 case "running":
1550 runningCount++
1551 case "restarting":
1552 restartingCount++
1553 case "paused":
1554 pausedCount++
1555 }
1556 } else {
1557 notFoundNames = append(notFoundNames, name)
1558 }
1559 }
1560 switch {
1561 case exitedCount == total:
1562 appInstall.Status = constant.StatusStopped
1563 case runningCount == total:
1564 appInstall.Status = constant.StatusRunning
1565 if oldStatus == constant.StatusRunning {
1566 return
1567 }
1568 case restartingCount == total:
1569 appInstall.Status = constant.StatusRestarting
1570 case pausedCount == total:
1571 appInstall.Status = constant.StatusPaused
1572 case len(notFoundNames) == total:
1573 if appInstall.Status == constant.StatusUpErr && !force {
1574 return
1575 }
1576 appInstall.Status = constant.StatusError
1577 appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(notFoundNames, ",")).Error()
1578 default:
1579 var msg string
1580 if exitedCount > 0 {
1581 msg = buserr.WithName("ErrContainerMsg", strings.Join(exitNames, ",")).Error()

Callers 3

syncAgentAppInstallsFunction · 0.85
syncAppInstallStatusFunction · 0.85
handleInstalledFunction · 0.85

Calls 2

SaveMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected