feat(renderer): add timeout for the renderer api

closes #4325
This commit is contained in:
bergquist
2016-03-10 16:02:10 +01:00
parent 0b6fee138a
commit 43073da7eb
2 changed files with 9 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"strconv"
)
type RenderOpts struct {
@@ -18,6 +19,7 @@ type RenderOpts struct {
Width string
Height string
SessionId string
Timeout string
}
func RenderToPng(params *RenderOpts) (string, error) {
@@ -60,8 +62,13 @@ func RenderToPng(params *RenderOpts) (string, error) {
close(done)
}()
timeout, err := strconv.Atoi(params.Timeout)
if err != nil {
timeout = 15
}
select {
case <-time.After(15 * time.Second):
case <-time.After(time.Duration(timeout) * time.Second):
if err := cmd.Process.Kill(); err != nil {
log.Error(4, "failed to kill: %v", err)
}