adds configurable debugging of startup of processes and print out some info from the chrome viable() function for debugging purposes

This commit is contained in:
Thomas Bøgh Fangel
2019-06-13 15:59:06 +02:00
parent cfea2b8d9d
commit bbd0a893b1
7 changed files with 83 additions and 35 deletions

View File

@@ -7,15 +7,19 @@ import (
"github.com/mafredri/cdp/devtool"
)
const (
warmupTime = 10 * time.Second
)
type chrome struct {
manager *processManager
}
// NewChrome retruns a Google Chrome
// headless process.
func NewChrome() Process {
func NewChrome(debug bool) Process {
return &chrome{
manager: &processManager{},
manager: &processManager{verbose: debug},
}
}
@@ -58,12 +62,20 @@ func (p *chrome) viable() bool {
// check if Google Chrome is correctly running.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err := devtool.New("http://localhost:9222").Version(ctx)
return err == nil
p.manager.notifyf(`%v: checking Chrome liveness via debug version endpoint
'http://localhost:9222/json/version'`, p.name())
v, err := devtool.New("http://localhost:9222").Version(ctx)
if err != nil {
p.manager.notifyf("%v: Chrome version endpoint returned error: %v", p.name(), err)
return false
}
p.manager.notifyf("%v: Chrome returned version info: %+v", p.name(), *v)
return true
}
func (p *chrome) warmup() {
time.Sleep(5 * time.Second)
p.manager.notifyf("%v: allowing Chrome %v to startup", p.name(), warmupTime)
time.Sleep(warmupTime)
}
// Compile-time checks to ensure type implements desired interfaces.