Commit ebdbb0c9 by Leonard Gram Committed by GitHub

Rendering: makes sure IsAvailable can be used during init of other services (#23817)

* Rendering: makes sure service knows if it is configured after Init()

* Rendering: refactor
parent 0284747c
...@@ -22,7 +22,11 @@ import ( ...@@ -22,7 +22,11 @@ import (
func init() { func init() {
remotecache.Register(&RenderUser{}) remotecache.Register(&RenderUser{})
registry.RegisterService(&RenderingService{}) registry.Register(&registry.Descriptor{
Name: "RenderingService",
Instance: &RenderingService{},
InitPriority: registry.High,
})
} }
const renderKeyPrefix = "render-%s" const renderKeyPrefix = "render-%s"
...@@ -68,7 +72,7 @@ func (rs *RenderingService) Init() error { ...@@ -68,7 +72,7 @@ func (rs *RenderingService) Init() error {
} }
func (rs *RenderingService) Run(ctx context.Context) error { func (rs *RenderingService) Run(ctx context.Context) error {
if rs.Cfg.RendererUrl != "" { if rs.remoteAvailable() {
rs.log = rs.log.New("renderer", "http") rs.log = rs.log.New("renderer", "http")
rs.log.Info("Backend rendering via external http server") rs.log.Info("Backend rendering via external http server")
rs.renderAction = rs.renderViaHttp rs.renderAction = rs.renderViaHttp
...@@ -76,7 +80,7 @@ func (rs *RenderingService) Run(ctx context.Context) error { ...@@ -76,7 +80,7 @@ func (rs *RenderingService) Run(ctx context.Context) error {
return nil return nil
} }
if plugins.Renderer != nil { if rs.pluginAvailable() {
rs.log = rs.log.New("renderer", "plugin") rs.log = rs.log.New("renderer", "plugin")
rs.pluginInfo = plugins.Renderer rs.pluginInfo = plugins.Renderer
...@@ -97,8 +101,16 @@ func (rs *RenderingService) Run(ctx context.Context) error { ...@@ -97,8 +101,16 @@ func (rs *RenderingService) Run(ctx context.Context) error {
return nil return nil
} }
func (rs *RenderingService) pluginAvailable() bool {
return plugins.Renderer != nil
}
func (rs *RenderingService) remoteAvailable() bool {
return rs.Cfg.RendererUrl != ""
}
func (rs *RenderingService) IsAvailable() bool { func (rs *RenderingService) IsAvailable() bool {
return rs.renderAction != nil return rs.remoteAvailable() || rs.pluginAvailable()
} }
func (rs *RenderingService) RenderErrorImage(err error) (*RenderResult, error) { func (rs *RenderingService) RenderErrorImage(err error) (*RenderResult, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment