App
This commit is contained in:
		
							parent
							
								
									7f552e5c8a
								
							
						
					
					
						commit
						d991f1abb5
					
				
							
								
								
									
										31
									
								
								app.go
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								app.go
									
									
									
									
									
								
							| @ -1,31 +0,0 @@ | ||||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"flag" | ||||
| 
 | ||||
| 	"github.com/kr/pretty" | ||||
| 	"github.com/localhots/confection" | ||||
| 	"github.com/localhots/yeast/chain" | ||||
| 	"github.com/localhots/yeast/core" | ||||
| 	"github.com/localhots/yeast/unit" | ||||
| ) | ||||
| 
 | ||||
| func init() { | ||||
| 	confection.SetupFlags() | ||||
| 	flag.Parse() | ||||
| } | ||||
| 
 | ||||
| func main() { | ||||
| 	core.InitConfig() | ||||
| 
 | ||||
| 	ub := unit.NewBank(core.Conf().UnitsConfig) | ||||
| 	ub.Reload() | ||||
| 
 | ||||
| 	cb := chain.NewBank(core.Conf().ChainsConfig, ub) | ||||
| 	cb.Reload() | ||||
| 
 | ||||
| 	pretty.Println(core.Conf()) | ||||
| 
 | ||||
| 	println("Waiting") | ||||
| 	select {} | ||||
| } | ||||
| @ -32,6 +32,8 @@ func (b *Bank) Chain(name string) *Chain { | ||||
| } | ||||
| 
 | ||||
| func (b *Bank) Reload() { | ||||
| 	b.units.Reload() | ||||
| 
 | ||||
| 	f, err := os.Open(b.config) | ||||
| 	if err != nil { | ||||
| 		panic("Failed to open chains config: " + b.config) | ||||
|  | ||||
							
								
								
									
										30
									
								
								core/app.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								core/app.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| package core | ||||
| 
 | ||||
| import ( | ||||
| 	"github.com/localhots/yeast/chain" | ||||
| 	"github.com/localhots/yeast/unit" | ||||
| ) | ||||
| 
 | ||||
| type ( | ||||
| 	App struct { | ||||
| 		config *Config | ||||
| 		chains *chain.Bank | ||||
| 	} | ||||
| ) | ||||
| 
 | ||||
| func NewApp() *App { | ||||
| 	a := &App{ | ||||
| 		config: &Config{}, | ||||
| 	} | ||||
| 	a.config.Init() | ||||
| 
 | ||||
| 	ub := unit.NewBank(a.Conf().UnitsConfig) | ||||
| 	a.chains = chain.NewBank(a.Conf().ChainsConfig, ub) | ||||
| 	a.chains.Reload() | ||||
| 
 | ||||
| 	return a | ||||
| } | ||||
| 
 | ||||
| func (a *App) Conf() Config { | ||||
| 	return a.config.conf.Config().(Config) | ||||
| } | ||||
| @ -8,6 +8,7 @@ import ( | ||||
| 
 | ||||
| type ( | ||||
| 	Config struct { | ||||
| 		conf         *confection.Manager | ||||
| 		ChainsConfig string `json:"chains_config_path" attrs:"required" title:"Chains config path"` | ||||
| 		UnitsConfig  string `json:"units_config_path" attrs:"required" title:"Units config path"` | ||||
| 		Python       Python `json:"python" title:"Python"` | ||||
| @ -18,21 +19,13 @@ type ( | ||||
| 	} | ||||
| ) | ||||
| 
 | ||||
| var ( | ||||
| 	conf *confection.Manager | ||||
| ) | ||||
| 
 | ||||
| func Conf() Config { | ||||
| 	return conf.Config().(Config) | ||||
| func (c *Config) Init() { | ||||
| 	c.conf = confection.New(*c, c.decoder) | ||||
| 	go c.conf.StartServer() | ||||
| 	c.conf.RequireConfig() | ||||
| } | ||||
| 
 | ||||
| func InitConfig() { | ||||
| 	conf = confection.New(Config{}, ConfigDecoder) | ||||
| 	go conf.StartServer() | ||||
| 	conf.RequireConfig() | ||||
| } | ||||
| 
 | ||||
| func ConfigDecoder(b []byte) interface{} { | ||||
| func (c *Config) decoder(b []byte) interface{} { | ||||
| 	var newConf Config | ||||
| 	if err := json.Unmarshal(b, &newConf); err != nil { | ||||
| 		panic(err) | ||||
|  | ||||
| @ -8,7 +8,10 @@ import ( | ||||
| ) | ||||
| 
 | ||||
| type ( | ||||
| 	Supervisor struct{} | ||||
| 	Supervisor struct { | ||||
| 		pythonBin     string | ||||
| 		pythonWrapper string | ||||
| 	} | ||||
| ) | ||||
| 
 | ||||
| // XXX: We're about to spawn hundreds of Python processes | ||||
| @ -21,8 +24,7 @@ func (s *Supervisor) StartAll(units []string) { | ||||
| 
 | ||||
| func (s *Supervisor) Start(name string) { | ||||
| 	fmt.Println("Starting unit: " + name) | ||||
| 	conf := Conf().Python | ||||
| 	cmd := exec.Command(conf.BinPath, conf.WrapperPath, name) | ||||
| 	cmd := exec.Command(s.pythonBin, s.pythonWrapper, name) | ||||
| 	cmd.Stdout = os.Stdout // Sorry | ||||
| 	if err := cmd.Start(); err != nil { | ||||
| 		fmt.Println("Failed to start unit: ", name) | ||||
|  | ||||
							
								
								
									
										22
									
								
								yeast.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								yeast.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"flag" | ||||
| 
 | ||||
| 	"github.com/kr/pretty" | ||||
| 	"github.com/localhots/confection" | ||||
| 	"github.com/localhots/yeast/core" | ||||
| ) | ||||
| 
 | ||||
| func init() { | ||||
| 	confection.SetupFlags() | ||||
| 	flag.Parse() | ||||
| } | ||||
| 
 | ||||
| func main() { | ||||
| 	app := core.NewApp() | ||||
| 	pretty.Println(app.Conf()) | ||||
| 
 | ||||
| 	println("Waiting") | ||||
| 	select {} | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user