✨ 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:
		| @@ -9,10 +9,10 @@ import ( | ||||
| 	"gopkg.in/yaml.v2" | ||||
| ) | ||||
|  | ||||
| var App *AppConfig | ||||
| var App *RoadApp | ||||
|  | ||||
| func ReadInConfig(root string) error { | ||||
| 	cfg := &AppConfig{ | ||||
| 	instance := &RoadApp{ | ||||
| 		Sites: []*SiteConfig{}, | ||||
| 	} | ||||
|  | ||||
| @@ -31,7 +31,7 @@ func ReadInConfig(root string) error { | ||||
|  | ||||
| 			// Extract file name as site id | ||||
| 			site.ID = strings.SplitN(filepath.Base(fp), ".", 2)[0] | ||||
| 			cfg.Sites = append(cfg.Sites, &site) | ||||
| 			instance.Sites = append(instance.Sites, &site) | ||||
| 		} | ||||
|  | ||||
| 		return nil | ||||
| @@ -39,7 +39,7 @@ func ReadInConfig(root string) error { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	App = cfg | ||||
| 	App = instance | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
| @@ -12,6 +12,7 @@ type ProcessConfig struct { | ||||
| 	Workdir  string     `json:"workdir" yaml:"workdir"` | ||||
| 	Command  []string   `json:"command" yaml:"command"` | ||||
| 	Prepares [][]string `json:"prepares" yaml:"prepares"` | ||||
| 	Preheat  bool       `json:"preheat" yaml:"preheat"` | ||||
|  | ||||
| 	Cmd *exec.Cmd `json:"-"` | ||||
| } | ||||
| @@ -20,7 +21,7 @@ func (v *ProcessConfig) BootProcess() error { | ||||
| 	if v.Cmd != nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	if err := v.PreapreProcess(); err != nil { | ||||
| 	if err := v.PrepareProcess(); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	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 { | ||||
| 		if len(script) <= 0 { | ||||
| 			continue | ||||
| @@ -78,3 +79,18 @@ func (v *ProcessConfig) StopProcess() error { | ||||
|  | ||||
| 	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" | ||||
| ) | ||||
|  | ||||
| type AppConfig struct { | ||||
| type RoadApp struct { | ||||
| 	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 { | ||||
| 		return errors.New("invalid configuration") | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user