mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Rename AddEventListenerCtx to AddEventListener and PublishCtx to Publish (#43566)
This commit is contained in:
parent
a0cf57b5b8
commit
65e60759fb
@ -206,7 +206,7 @@ func (hs *HTTPServer) CompleteInvite(c *models.ReqContext) response.Response {
|
||||
return response.Error(500, "failed to create user", err)
|
||||
}
|
||||
|
||||
if err := bus.PublishCtx(c.Req.Context(), &events.SignUpCompleted{
|
||||
if err := bus.Publish(c.Req.Context(), &events.SignUpCompleted{
|
||||
Name: user.NameOrFallback(),
|
||||
Email: user.Email,
|
||||
}); err != nil {
|
||||
|
@ -55,7 +55,7 @@ func SignUp(c *models.ReqContext) response.Response {
|
||||
return response.Error(500, "Failed to create signup", err)
|
||||
}
|
||||
|
||||
if err := bus.PublishCtx(c.Req.Context(), &events.SignUpStarted{
|
||||
if err := bus.Publish(c.Req.Context(), &events.SignUpStarted{
|
||||
Email: form.Email,
|
||||
Code: cmd.Code,
|
||||
}); err != nil {
|
||||
@ -102,7 +102,7 @@ func (hs *HTTPServer) SignUpStep2(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// publish signup event
|
||||
if err := bus.PublishCtx(c.Req.Context(), &events.SignUpCompleted{
|
||||
if err := bus.Publish(c.Req.Context(), &events.SignUpCompleted{
|
||||
Email: user.Email,
|
||||
Name: user.NameOrFallback(),
|
||||
}); err != nil {
|
||||
|
@ -29,7 +29,7 @@ type TransactionManager interface {
|
||||
type Bus interface {
|
||||
Dispatch(ctx context.Context, msg Msg) error
|
||||
|
||||
PublishCtx(ctx context.Context, msg Msg) error
|
||||
Publish(ctx context.Context, msg Msg) error
|
||||
|
||||
// InTransaction starts a transaction and store it in the context.
|
||||
// The caller can then pass a function with multiple DispatchCtx calls that
|
||||
@ -39,7 +39,7 @@ type Bus interface {
|
||||
|
||||
AddHandler(handler HandlerFunc)
|
||||
|
||||
AddEventListenerCtx(handler HandlerFunc)
|
||||
AddEventListener(handler HandlerFunc)
|
||||
|
||||
// SetTransactionManager allows the user to replace the internal
|
||||
// noop TransactionManager that is responsible for managing
|
||||
@ -127,7 +127,7 @@ func (b *InProcBus) Dispatch(ctx context.Context, msg Msg) error {
|
||||
}
|
||||
|
||||
// PublishCtx function publish a message to the bus listener.
|
||||
func (b *InProcBus) PublishCtx(ctx context.Context, msg Msg) error {
|
||||
func (b *InProcBus) Publish(ctx context.Context, msg Msg) error {
|
||||
var msgName = reflect.TypeOf(msg).Elem().Name()
|
||||
|
||||
var params = []reflect.Value{}
|
||||
@ -183,7 +183,7 @@ func (b *InProcBus) GetHandlerCtx(name string) HandlerFunc {
|
||||
return b.handlersWithCtx[name]
|
||||
}
|
||||
|
||||
func (b *InProcBus) AddEventListenerCtx(handler HandlerFunc) {
|
||||
func (b *InProcBus) AddEventListener(handler HandlerFunc) {
|
||||
handlerType := reflect.TypeOf(handler)
|
||||
eventName := handlerType.In(1).Elem().Name()
|
||||
_, exists := b.listenersWithCtx[eventName]
|
||||
@ -201,16 +201,16 @@ func AddHandler(implName string, handler HandlerFunc) {
|
||||
|
||||
// AddEventListenerCtx attaches a handler function to the event listener.
|
||||
// Package level function.
|
||||
func AddEventListenerCtx(handler HandlerFunc) {
|
||||
globalBus.AddEventListenerCtx(handler)
|
||||
func AddEventListener(handler HandlerFunc) {
|
||||
globalBus.AddEventListener(handler)
|
||||
}
|
||||
|
||||
func Dispatch(ctx context.Context, msg Msg) error {
|
||||
return globalBus.Dispatch(ctx, msg)
|
||||
}
|
||||
|
||||
func PublishCtx(ctx context.Context, msg Msg) error {
|
||||
return globalBus.PublishCtx(ctx, msg)
|
||||
func Publish(ctx context.Context, msg Msg) error {
|
||||
return globalBus.Publish(ctx, msg)
|
||||
}
|
||||
|
||||
func GetHandlerCtx(name string) HandlerFunc {
|
||||
|
@ -127,12 +127,12 @@ func TestEventPublish(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddEventListenerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddEventListener(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
|
||||
err := bus.PublishCtx(context.Background(), &testQuery{})
|
||||
err := bus.Publish(context.Background(), &testQuery{})
|
||||
require.NoError(t, err, "unable to publish event")
|
||||
|
||||
require.True(t, invoked)
|
||||
@ -141,7 +141,7 @@ func TestEventPublish(t *testing.T) {
|
||||
func TestEventPublish_NoRegisteredListener(t *testing.T) {
|
||||
bus := New()
|
||||
|
||||
err := bus.PublishCtx(context.Background(), &testQuery{})
|
||||
err := bus.Publish(context.Background(), &testQuery{})
|
||||
require.NoError(t, err, "unable to publish event")
|
||||
}
|
||||
|
||||
@ -150,12 +150,12 @@ func TestEventCtxPublishCtx(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddEventListenerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddEventListener(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
|
||||
err := bus.PublishCtx(context.Background(), &testQuery{})
|
||||
err := bus.Publish(context.Background(), &testQuery{})
|
||||
require.NoError(t, err, "unable to publish event")
|
||||
|
||||
require.True(t, invoked)
|
||||
@ -164,7 +164,7 @@ func TestEventCtxPublishCtx(t *testing.T) {
|
||||
func TestEventPublishCtx_NoRegisteredListener(t *testing.T) {
|
||||
bus := New()
|
||||
|
||||
err := bus.PublishCtx(context.Background(), &testQuery{})
|
||||
err := bus.Publish(context.Background(), &testQuery{})
|
||||
require.NoError(t, err, "unable to publish event")
|
||||
}
|
||||
|
||||
@ -173,12 +173,12 @@ func TestEventPublishCtx(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddEventListenerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddEventListener(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
|
||||
err := bus.PublishCtx(context.Background(), &testQuery{})
|
||||
err := bus.Publish(context.Background(), &testQuery{})
|
||||
require.NoError(t, err, "unable to publish event")
|
||||
|
||||
require.True(t, invoked)
|
||||
@ -189,12 +189,12 @@ func TestEventCtxPublish(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddEventListenerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddEventListener(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
|
||||
err := bus.PublishCtx(context.Background(), &testQuery{})
|
||||
err := bus.Publish(context.Background(), &testQuery{})
|
||||
require.NoError(t, err, "unable to publish event")
|
||||
|
||||
require.True(t, invoked)
|
||||
|
@ -19,7 +19,7 @@ func ProvideService(pluginStore plugins.Store, pluginDashboardManager plugins.Pl
|
||||
pluginDashboardManager: pluginDashboardManager,
|
||||
logger: log.New("plugindashboards"),
|
||||
}
|
||||
bus.AddEventListenerCtx(s.handlePluginStateChanged)
|
||||
bus.AddEventListener(s.handlePluginStateChanged)
|
||||
s.updateAppDashboards()
|
||||
return s
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ func ProvideService(bus bus.Bus, cfg *setting.Cfg) (*NotificationService, error)
|
||||
ns.Bus.AddHandler(ns.sendEmailCommandHandlerSync)
|
||||
ns.Bus.AddHandler(ns.SendWebhookSync)
|
||||
|
||||
ns.Bus.AddEventListenerCtx(ns.signUpStartedHandler)
|
||||
ns.Bus.AddEventListenerCtx(ns.signUpCompletedHandler)
|
||||
ns.Bus.AddEventListener(ns.signUpStartedHandler)
|
||||
ns.Bus.AddEventListener(ns.signUpCompletedHandler)
|
||||
|
||||
mailTemplates = template.New("name")
|
||||
mailTemplates.Funcs(template.FuncMap{
|
||||
|
@ -97,7 +97,7 @@ func TestDataAccess(t *testing.T) {
|
||||
sqlStore := InitTestDB(t)
|
||||
|
||||
var created *events.DataSourceCreated
|
||||
bus.AddEventListenerCtx(func(ctx context.Context, e *events.DataSourceCreated) error {
|
||||
bus.AddEventListener(func(ctx context.Context, e *events.DataSourceCreated) error {
|
||||
created = e
|
||||
return nil
|
||||
})
|
||||
@ -241,7 +241,7 @@ func TestDataAccess(t *testing.T) {
|
||||
ds := initDatasource(sqlStore)
|
||||
|
||||
var deleted *events.DataSourceDeleted
|
||||
bus.AddEventListenerCtx(func(ctx context.Context, e *events.DataSourceDeleted) error {
|
||||
bus.AddEventListener(func(ctx context.Context, e *events.DataSourceDeleted) error {
|
||||
deleted = e
|
||||
return nil
|
||||
})
|
||||
|
@ -68,7 +68,7 @@ func inTransactionWithRetryCtx(ctx context.Context, engine *xorm.Engine, callbac
|
||||
|
||||
if len(sess.events) > 0 {
|
||||
for _, e := range sess.events {
|
||||
if err = bus.PublishCtx(ctx, e); err != nil {
|
||||
if err = bus.Publish(ctx, e); err != nil {
|
||||
tsclogger.Error("Failed to publish event after commit.", "error", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user