mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 04:32:15 +01:00
handling webhookURLTimeout
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/printer"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/printer"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
||||||
"github.com/thecodingmachine/gotenberg/internal/pkg/xrand"
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xrand"
|
||||||
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -260,6 +261,14 @@ func convertAsync(ctx context.Context, p printer.Printer, filename, fpath string
|
|||||||
const op = "xhttp.convertAsync"
|
const op = "xhttp.convertAsync"
|
||||||
logger := ctx.XLogger()
|
logger := ctx.XLogger()
|
||||||
r := ctx.MustResource()
|
r := ctx.MustResource()
|
||||||
|
webhookURL, err := r.StringArg(resource.WebhookURLArgKey, "")
|
||||||
|
if err != nil {
|
||||||
|
return xerror.New(op, err)
|
||||||
|
}
|
||||||
|
webhookURLTimeout, err := resource.WebhookURLTimeoutArg(r, ctx.Config())
|
||||||
|
if err != nil {
|
||||||
|
return xerror.New(op, err)
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
defer r.Close() // nolint: errcheck
|
defer r.Close() // nolint: errcheck
|
||||||
if err := p.Print(fpath); err != nil {
|
if err := p.Print(fpath); err != nil {
|
||||||
@@ -274,20 +283,16 @@ func convertAsync(ctx context.Context, p printer.Printer, filename, fpath string
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer f.Close() // nolint: errcheck
|
defer f.Close() // nolint: errcheck
|
||||||
webhookURL, err := r.StringArg(resource.WebhookURLArgKey, "")
|
|
||||||
if err != nil {
|
|
||||||
xerr := xerror.New(op, err)
|
|
||||||
logger.ErrorOp(xerror.Op(xerr), xerr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logger.DebugfOp(
|
logger.DebugfOp(
|
||||||
op,
|
op,
|
||||||
"sending result file '%s' to '%s'",
|
"sending result file '%s' to '%s'",
|
||||||
filename,
|
filename,
|
||||||
webhookURL,
|
webhookURL,
|
||||||
)
|
)
|
||||||
// TODO timeout
|
httpclient := &http.Client{
|
||||||
resp, err := http.Post(webhookURL, "application/pdf", f) /* #nosec */
|
Timeout: xtime.Duration(webhookURLTimeout),
|
||||||
|
}
|
||||||
|
resp, err := httpclient.Post(webhookURL, "application/pdf", f) /* #nosec */
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xerr := xerror.New(op, err)
|
xerr := xerror.New(op, err)
|
||||||
logger.ErrorOp(xerror.Op(xerr), xerr)
|
logger.ErrorOp(xerror.Op(xerr), xerr)
|
||||||
|
|||||||
Reference in New Issue
Block a user