realize run fixed

This commit is contained in:
alessio 2016-10-14 10:47:43 +02:00
parent 434fe5f43e
commit 64ad2dcaf3
4 changed files with 20 additions and 12 deletions

View File

@ -15,9 +15,9 @@ func (h *Blueprint) Run() error {
if err == nil { if err == nil {
// loop projects // loop projects
wg.Add(len(h.Projects)) wg.Add(len(h.Projects))
for _, v := range h.Projects { for k := range h.Projects {
v.parent = h h.Projects[k].parent = h
go v.watching() go h.Projects[k].watching()
} }
wg.Wait() wg.Wait()
return nil return nil

View File

@ -29,10 +29,10 @@ 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()) p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "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") p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Ended"})
log.Println(pname(p.Name, 2), ":", RedS("Ended")) log.Println(pname(p.Name, 2), ":", RedS("Ended"))
go sync() go sync()
wr.Done() wr.Done()
@ -59,9 +59,9 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
select { select {
default: default:
if isError { if isError {
p.Buffer.StdErr = append(p.Buffer.StdErr, output.Text()) p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: output.Text()})
} else { } else {
p.Buffer.StdOut = append(p.Buffer.StdOut, output.Text()) p.Buffer.StdOut = append(p.Buffer.StdOut, BufferOut{Time: time.Now(), Text: output.Text()})
} }
go sync() go sync()
@ -80,6 +80,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
} }
close(stop) close(stop)
} }
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Started"})
go scanner(stopOutput, execOutput, false) go scanner(stopOutput, execOutput, false)
go scanner(stopError, execError, true) go scanner(stopError, execError, true)

View File

@ -26,12 +26,12 @@ type logWriter struct{}
type Blueprint struct { type Blueprint struct {
Projects []Project `yaml:"projects,omitempty"` Projects []Project `yaml:"projects,omitempty"`
Files map[string]string `yaml:"-"` Files map[string]string `yaml:"-"`
Sync chan string Sync chan string `yaml:"-"`
} }
// Project defines the informations of a single project // Project defines the informations of a single project
type Project struct { type Project struct {
LastChangedOn time.Time LastChangedOn time.Time `yaml:"-"`
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"`
@ -60,9 +60,14 @@ type Watcher struct {
// Buffer struct for buffering outputs // Buffer struct for buffering outputs
type Buffer struct { type Buffer struct {
StdOut []string StdOut []BufferOut
StdLog []string StdLog []BufferOut
StdErr []string StdErr []BufferOut
}
type BufferOut struct {
Time time.Time
Text string
} }
// Initialize the application // Initialize the application

View File

@ -18,6 +18,8 @@ import (
// Watching method is the main core. It manages the livereload and the watching // Watching method is the main core. It manages the livereload and the watching
func (p *Project) watching() { func (p *Project) watching() {
log.Println(p)
var wr sync.WaitGroup var wr sync.WaitGroup
var watcher *fsnotify.Watcher var watcher *fsnotify.Watcher