mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 04:12:16 +01:00
process load balancing: broken but in progress
This commit is contained in:
@@ -13,7 +13,8 @@ import (
|
||||
"github.com/thecodingmachine/gotenberg/internal/app/xhttp/pkg/resource"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/conf"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/normalize"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/pm2"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/prinery"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/process"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xlog"
|
||||
)
|
||||
@@ -21,20 +22,31 @@ import (
|
||||
// Context extends the default echo.Context.
|
||||
type Context struct {
|
||||
echo.Context
|
||||
logger xlog.Logger
|
||||
config conf.Config
|
||||
processes []pm2.Process
|
||||
resource resource.Resource
|
||||
startTime time.Time
|
||||
logger xlog.Logger
|
||||
config conf.Config
|
||||
manager process.Manager
|
||||
chromePrinery *prinery.Prinery
|
||||
sofficePrinery *prinery.Prinery
|
||||
resource resource.Resource
|
||||
startTime time.Time
|
||||
}
|
||||
|
||||
// New creates a new Context.
|
||||
func New(c echo.Context, logger xlog.Logger, config conf.Config, processes ...pm2.Process) Context {
|
||||
func New(
|
||||
c echo.Context,
|
||||
logger xlog.Logger,
|
||||
config conf.Config,
|
||||
manager process.Manager,
|
||||
chromePrinery *prinery.Prinery,
|
||||
sofficePrinery *prinery.Prinery,
|
||||
) Context {
|
||||
return Context{
|
||||
c,
|
||||
logger,
|
||||
config,
|
||||
processes,
|
||||
manager,
|
||||
chromePrinery,
|
||||
sofficePrinery,
|
||||
resource.Resource{},
|
||||
time.Now(),
|
||||
}
|
||||
@@ -77,17 +89,52 @@ func (ctx Context) Config() conf.Config {
|
||||
// one of the processes is not viable.
|
||||
func (ctx Context) ProcessesHealthcheck() error {
|
||||
const op string = "context.Context.ProcessesHealthcheck"
|
||||
for _, process := range ctx.processes {
|
||||
if !process.IsViable() {
|
||||
processes := ctx.manager.All()
|
||||
for _, p := range processes {
|
||||
if !ctx.manager.IsViable(p) {
|
||||
return xerror.New(
|
||||
op,
|
||||
fmt.Errorf("'%s' is not viable", process.Fullname()),
|
||||
fmt.Errorf("'%s' is not viable", p.ID()),
|
||||
)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
MustChromePrinery returns the instance of
|
||||
prinery.Prinery associated with the Context.
|
||||
|
||||
This prinery.Prinery handles Google Chrome
|
||||
headless.
|
||||
|
||||
It panics if no instance of prinery.Prinery.
|
||||
*/
|
||||
func (ctx Context) MustChromePrinery() *prinery.Prinery {
|
||||
const op string = "context.Context.MustChromePrinery"
|
||||
if ctx.chromePrinery == nil {
|
||||
panic(fmt.Sprintf("%s: unable to retrieve the instance of Google Chrome Headless prinery.Prinery from our custom context.Context", op))
|
||||
}
|
||||
return ctx.chromePrinery
|
||||
}
|
||||
|
||||
/*
|
||||
MustSofficePrinery returns the instance of
|
||||
prinery.Prinery associated with the Context.
|
||||
|
||||
This prinery.Prinery handles LibreOffice
|
||||
headless.
|
||||
|
||||
It panics if no instance of prinery.Prinery.
|
||||
*/
|
||||
func (ctx Context) MustSofficePrinery() *prinery.Prinery {
|
||||
const op string = "context.Context.MustSofficePrinery"
|
||||
if ctx.sofficePrinery == nil {
|
||||
panic(fmt.Sprintf("%s: unable to retrieve the instance of LibreOffice Headless prinery.Prinery from our custom context.Context", op))
|
||||
}
|
||||
return ctx.sofficePrinery
|
||||
}
|
||||
|
||||
// WithResource creates a resource.Resource and
|
||||
// adds it to the Context.
|
||||
func (ctx *Context) WithResource(directoryName string) error {
|
||||
|
||||
Reference in New Issue
Block a user