rendering: Added concurrent rendering limits

This commit is contained in:
Torkel Ödegaard
2018-09-24 15:58:22 +02:00
parent b41333d4b9
commit 4dab595ed7
11 changed files with 44 additions and 11 deletions

View File

@ -24,12 +24,13 @@ func init() {
}
type RenderingService struct {
log log.Logger
pluginClient *plugin.Client
grpcPlugin pluginModel.RendererPlugin
pluginInfo *plugins.RendererPlugin
renderAction renderFunc
domain string
log log.Logger
pluginClient *plugin.Client
grpcPlugin pluginModel.RendererPlugin
pluginInfo *plugins.RendererPlugin
renderAction renderFunc
domain string
inProgressCount int
Cfg *setting.Cfg `inject:""`
}
@ -89,7 +90,27 @@ func (rs *RenderingService) Run(ctx context.Context) error {
return err
}
func (rs *RenderingService) getLimit(isAlerting bool) int {
if isAlerting {
return rs.Cfg.RendererLimitAlerting
} else {
return rs.Cfg.RendererLimit
}
}
func (rs *RenderingService) Render(ctx context.Context, opts Opts) (*RenderResult, error) {
if rs.inProgressCount > rs.getLimit(opts.IsAlert) {
return &RenderResult{
FilePath: filepath.Join(setting.HomePath, "public/img/rendering_limit.png"),
}, nil
}
defer func() {
rs.inProgressCount -= 1
}()
rs.inProgressCount += 1
if rs.renderAction != nil {
return rs.renderAction(ctx, opts)
} else {