✨ Process lifecycle management
This commit is contained in:
@@ -8,8 +8,13 @@ import (
|
||||
)
|
||||
|
||||
func getApplications(c *fiber.Ctx) error {
|
||||
applications := lo.FlatMap(navi.R.Regions, func(item *navi.Region, idx int) []warden.Application {
|
||||
return item.Applications
|
||||
applications := lo.FlatMap(navi.R.Regions, func(item *navi.Region, idx int) []warden.ApplicationInfo {
|
||||
return lo.Map(item.Applications, func(item warden.Application, index int) warden.ApplicationInfo {
|
||||
return warden.ApplicationInfo{
|
||||
Application: item,
|
||||
Status: warden.GetFromPool(item.ID).Status,
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return c.JSON(applications)
|
||||
@@ -24,3 +29,45 @@ func getApplicationLogs(c *fiber.Ctx) error {
|
||||
return c.SendString(instance.Logs())
|
||||
}
|
||||
}
|
||||
|
||||
func letApplicationStart(c *fiber.Ctx) error {
|
||||
if instance, ok := lo.Find(warden.InstancePool, func(item *warden.AppInstance) bool {
|
||||
return item.Manifest.ID == c.Params("id")
|
||||
}); !ok {
|
||||
return fiber.NewError(fiber.StatusNotFound)
|
||||
} else {
|
||||
if err := instance.Wake(); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func letApplicationStop(c *fiber.Ctx) error {
|
||||
if instance, ok := lo.Find(warden.InstancePool, func(item *warden.AppInstance) bool {
|
||||
return item.Manifest.ID == c.Params("id")
|
||||
}); !ok {
|
||||
return fiber.NewError(fiber.StatusNotFound)
|
||||
} else {
|
||||
if err := instance.Stop(); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func letApplicationRestart(c *fiber.Ctx) error {
|
||||
if instance, ok := lo.Find(warden.InstancePool, func(item *warden.AppInstance) bool {
|
||||
return item.Manifest.ID == c.Params("id")
|
||||
}); !ok {
|
||||
return fiber.NewError(fiber.StatusNotFound)
|
||||
} else {
|
||||
if err := instance.Stop(); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
if err := instance.Start(); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
|
@@ -49,6 +49,9 @@ func InitSideload() *fiber.App {
|
||||
cgi.Get("/regions/cfg/:id", getRegionConfig)
|
||||
cgi.Get("/applications", getApplications)
|
||||
cgi.Get("/applications/:id/logs", getApplicationLogs)
|
||||
cgi.Post("/applications/:id/start", letApplicationStart)
|
||||
cgi.Post("/applications/:id/stop", letApplicationStop)
|
||||
cgi.Post("/applications/:id/restart", letApplicationRestart)
|
||||
|
||||
cgi.Post("/reload", doReload)
|
||||
}
|
||||
|
Reference in New Issue
Block a user