Added logs info on WebSocket API
This commit is contained in:
parent
c785adb415
commit
434fe5f43e
|
@ -16,6 +16,10 @@ import (
|
||||||
// GoRun is an implementation of the bin execution
|
// GoRun is an implementation of the bin execution
|
||||||
func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error {
|
func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error {
|
||||||
|
|
||||||
|
sync := func() {
|
||||||
|
p.parent.Sync <- "sync"
|
||||||
|
}
|
||||||
|
|
||||||
var build *exec.Cmd
|
var build *exec.Cmd
|
||||||
if len(p.Params) != 0 {
|
if len(p.Params) != 0 {
|
||||||
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)), p.Params...)
|
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)), p.Params...)
|
||||||
|
@ -25,9 +29,12 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
build.Dir = p.base
|
build.Dir = p.base
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := build.Process.Kill(); err != nil {
|
if err := build.Process.Kill(); err != nil {
|
||||||
|
p.Buffer.StdLog = append(p.Buffer.StdLog, "Failed to stop: "+err.Error())
|
||||||
log.Fatal(Red("Failed to stop: "), Red(err))
|
log.Fatal(Red("Failed to stop: "), Red(err))
|
||||||
}
|
}
|
||||||
|
p.Buffer.StdLog = append(p.Buffer.StdLog, "Ended")
|
||||||
log.Println(pname(p.Name, 2), ":", RedS("Ended"))
|
log.Println(pname(p.Name, 2), ":", RedS("Ended"))
|
||||||
|
go sync()
|
||||||
wr.Done()
|
wr.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -56,7 +63,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
} else {
|
} else {
|
||||||
p.Buffer.StdOut = append(p.Buffer.StdOut, output.Text())
|
p.Buffer.StdOut = append(p.Buffer.StdOut, output.Text())
|
||||||
}
|
}
|
||||||
go func() { p.parent.Sync <- "sync" }()
|
go sync()
|
||||||
|
|
||||||
if p.Watcher.Output["cli"] {
|
if p.Watcher.Output["cli"] {
|
||||||
log.Println(pname(p.Name, 3), ":", BlueS(output.Text()))
|
log.Println(pname(p.Name, 3), ":", BlueS(output.Text()))
|
||||||
|
|
|
@ -31,7 +31,7 @@ type Blueprint struct {
|
||||||
|
|
||||||
// Project defines the informations of a single project
|
// Project defines the informations of a single project
|
||||||
type Project struct {
|
type Project struct {
|
||||||
reload time.Time
|
LastChangedOn time.Time
|
||||||
base string
|
base string
|
||||||
Name string `yaml:"app_name,omitempty"`
|
Name string `yaml:"app_name,omitempty"`
|
||||||
Path string `yaml:"app_path,omitempty"`
|
Path string `yaml:"app_path,omitempty"`
|
||||||
|
|
|
@ -43,13 +43,13 @@ func (p *Project) watching() {
|
||||||
}
|
}
|
||||||
|
|
||||||
go p.routines(channel, &wr)
|
go p.routines(channel, &wr)
|
||||||
p.reload = time.Now().Truncate(time.Second)
|
p.LastChangedOn = time.Now().Truncate(time.Second)
|
||||||
|
|
||||||
// waiting for an event
|
// waiting for an event
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher.Events:
|
||||||
if time.Now().Truncate(time.Second).After(p.reload) {
|
if time.Now().Truncate(time.Second).After(p.LastChangedOn) {
|
||||||
if event.Op&fsnotify.Chmod == fsnotify.Chmod {
|
if event.Op&fsnotify.Chmod == fsnotify.Chmod {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func (p *Project) watching() {
|
||||||
log.Fatal(Red(err))
|
log.Fatal(Red(err))
|
||||||
} else {
|
} else {
|
||||||
go p.routines(channel, &wr)
|
go p.routines(channel, &wr)
|
||||||
p.reload = time.Now().Truncate(time.Second)
|
p.LastChangedOn = time.Now().Truncate(time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,9 @@ func (s *Server) Start() {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Use(middleware.Gzip())
|
e.Use(middleware.Gzip())
|
||||||
e.GET("/", func(c echo.Context) error {
|
e.GET("/", func(c echo.Context) error {
|
||||||
return c.JSON(200, s.Blueprint.Projects)
|
|
||||||
//return render(c, "server/assets/index.html")
|
//return render(c, "server/assets/index.html")
|
||||||
})
|
})
|
||||||
|
e.GET("/", standard.WrapHandler(s.projects()))
|
||||||
e.GET("/projects", standard.WrapHandler(s.projects()))
|
|
||||||
go e.Run(standard.New(":5000"))
|
go e.Run(standard.New(":5000"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue