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
|
||||
func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) error {
|
||||
|
||||
sync := func() {
|
||||
p.parent.Sync <- "sync"
|
||||
}
|
||||
|
||||
var build *exec.Cmd
|
||||
if len(p.Params) != 0 {
|
||||
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
|
||||
defer func() {
|
||||
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))
|
||||
}
|
||||
p.Buffer.StdLog = append(p.Buffer.StdLog, "Ended")
|
||||
log.Println(pname(p.Name, 2), ":", RedS("Ended"))
|
||||
go sync()
|
||||
wr.Done()
|
||||
}()
|
||||
|
||||
|
@ -56,7 +63,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
|||
} else {
|
||||
p.Buffer.StdOut = append(p.Buffer.StdOut, output.Text())
|
||||
}
|
||||
go func() { p.parent.Sync <- "sync" }()
|
||||
go sync()
|
||||
|
||||
if p.Watcher.Output["cli"] {
|
||||
log.Println(pname(p.Name, 3), ":", BlueS(output.Text()))
|
||||
|
|
|
@ -31,7 +31,7 @@ type Blueprint struct {
|
|||
|
||||
// Project defines the informations of a single project
|
||||
type Project struct {
|
||||
reload time.Time
|
||||
LastChangedOn time.Time
|
||||
base string
|
||||
Name string `yaml:"app_name,omitempty"`
|
||||
Path string `yaml:"app_path,omitempty"`
|
||||
|
|
|
@ -43,13 +43,13 @@ func (p *Project) watching() {
|
|||
}
|
||||
|
||||
go p.routines(channel, &wr)
|
||||
p.reload = time.Now().Truncate(time.Second)
|
||||
p.LastChangedOn = time.Now().Truncate(time.Second)
|
||||
|
||||
// waiting for an event
|
||||
for {
|
||||
select {
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func (p *Project) watching() {
|
|||
log.Fatal(Red(err))
|
||||
} else {
|
||||
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.Use(middleware.Gzip())
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
return c.JSON(200, s.Blueprint.Projects)
|
||||
//return render(c, "server/assets/index.html")
|
||||
})
|
||||
|
||||
e.GET("/projects", standard.WrapHandler(s.projects()))
|
||||
e.GET("/", standard.WrapHandler(s.projects()))
|
||||
go e.Run(standard.New(":5000"))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue