This commit is contained in:
Julien Neuhart
2019-04-14 17:07:45 +02:00
committed by GitHub
parent c4222e0981
commit 194670c3bf
63 changed files with 2114 additions and 1503 deletions

View File

@@ -2,30 +2,36 @@ package pm2
import (
"context"
"fmt"
"time"
"github.com/mafredri/cdp/devtool"
"github.com/thecodingmachine/gotenberg/internal/pkg/notify"
)
// Chrome facilitates starting or shutting down
// Chrome headless with PM2.
type Chrome struct{}
// Launch starts Chrome headless with PM2.
func (c *Chrome) Launch() error {
return launch(c)
type chrome struct {
manager *processManager
}
// Shutdown stops Chrome headless and
// removes it from the list of PM2
// processes.
func (c *Chrome) Shutdown() error {
return shutdown(c)
// NewChrome retruns a Google Chrome
// headless process.
func NewChrome() Process {
return &chrome{
manager: &processManager{},
}
}
func (c *Chrome) getArgs() []string {
func (p *chrome) Fullname() string {
return "Google Chrome headless"
}
func (p *chrome) Start() error {
return p.manager.start(p)
}
func (p *chrome) Shutdown() error {
return p.manager.shutdown(p)
}
func (p *chrome) args() []string {
return []string{
"--no-sandbox",
"--headless",
@@ -44,28 +50,23 @@ func (c *Chrome) getArgs() []string {
}
}
func (c *Chrome) getName() string {
func (p *chrome) name() string {
return "google-chrome-stable"
}
func (c *Chrome) getFullname() string {
return "Chrome headless"
}
func (c *Chrome) isViable() bool {
// check if Chrome is correctly running.
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
}
func (c *Chrome) warmup() {
notify.Println(fmt.Sprintf("warming-up %s", c.getFullname()))
func (p *chrome) warmup() {
time.Sleep(5 * time.Second)
}
// Compile-time checks to ensure type implements desired interfaces.
var (
_ = Process(new(Chrome))
_ = Process(new(chrome))
)