✨ Preheat Process
All checks were successful
release-nightly / build-docker (push) Successful in 1m15s
All checks were successful
release-nightly / build-docker (push) Successful in 1m15s
This commit is contained in:
parent
ed2b65355c
commit
426af568dc
@ -9,10 +9,10 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var App *AppConfig
|
var App *RoadApp
|
||||||
|
|
||||||
func ReadInConfig(root string) error {
|
func ReadInConfig(root string) error {
|
||||||
cfg := &AppConfig{
|
instance := &RoadApp{
|
||||||
Sites: []*SiteConfig{},
|
Sites: []*SiteConfig{},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ func ReadInConfig(root string) error {
|
|||||||
|
|
||||||
// Extract file name as site id
|
// Extract file name as site id
|
||||||
site.ID = strings.SplitN(filepath.Base(fp), ".", 2)[0]
|
site.ID = strings.SplitN(filepath.Base(fp), ".", 2)[0]
|
||||||
cfg.Sites = append(cfg.Sites, &site)
|
instance.Sites = append(instance.Sites, &site)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -39,7 +39,7 @@ func ReadInConfig(root string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
App = cfg
|
App = instance
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ type ProcessConfig struct {
|
|||||||
Workdir string `json:"workdir" yaml:"workdir"`
|
Workdir string `json:"workdir" yaml:"workdir"`
|
||||||
Command []string `json:"command" yaml:"command"`
|
Command []string `json:"command" yaml:"command"`
|
||||||
Prepares [][]string `json:"prepares" yaml:"prepares"`
|
Prepares [][]string `json:"prepares" yaml:"prepares"`
|
||||||
|
Preheat bool `json:"preheat" yaml:"preheat"`
|
||||||
|
|
||||||
Cmd *exec.Cmd `json:"-"`
|
Cmd *exec.Cmd `json:"-"`
|
||||||
}
|
}
|
||||||
@ -20,7 +21,7 @@ func (v *ProcessConfig) BootProcess() error {
|
|||||||
if v.Cmd != nil {
|
if v.Cmd != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := v.PreapreProcess(); err != nil {
|
if err := v.PrepareProcess(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if v.Cmd == nil {
|
if v.Cmd == nil {
|
||||||
@ -41,7 +42,7 @@ func (v *ProcessConfig) BootProcess() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ProcessConfig) PreapreProcess() error {
|
func (v *ProcessConfig) PrepareProcess() error {
|
||||||
for _, script := range v.Prepares {
|
for _, script := range v.Prepares {
|
||||||
if len(script) <= 0 {
|
if len(script) <= 0 {
|
||||||
continue
|
continue
|
||||||
@ -78,3 +79,18 @@ func (v *ProcessConfig) StopProcess() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *RoadApp) PreheatProcesses() {
|
||||||
|
var processes []*ProcessConfig
|
||||||
|
for _, site := range v.Sites {
|
||||||
|
for _, process := range site.Processes {
|
||||||
|
if process.Preheat {
|
||||||
|
processes = append(processes, process)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, process := range processes {
|
||||||
|
process.BootProcess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,11 +8,11 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppConfig struct {
|
type RoadApp struct {
|
||||||
Sites []*SiteConfig `json:"sites"`
|
Sites []*SiteConfig `json:"sites"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *AppConfig) Forward(ctx *fiber.Ctx, site *SiteConfig) error {
|
func (v *RoadApp) Forward(ctx *fiber.Ctx, site *SiteConfig) error {
|
||||||
if len(site.Upstreams) == 0 {
|
if len(site.Upstreams) == 0 {
|
||||||
return errors.New("invalid configuration")
|
return errors.New("invalid configuration")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user