Live: proxy subscribe data for subscribe and runstream plugin calls (#42824)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Alexander Emelin
2021-12-14 20:12:00 +03:00
committed by GitHub
co-authored by Ryan McKinley
parent d2c5dac76f
commit f4cc353225
15 changed files with 62 additions and 45 deletions
+5 -2
View File
@@ -136,7 +136,7 @@ func (s *Manager) handleDatasourceEvent(orgID int64, dsUID string, resubmit bool
if resubmit {
// Re-submit streams.
for _, sr := range resubmitRequests {
_, err := s.SubmitStream(s.baseCtx, sr.user, sr.Channel, sr.Path, sr.PluginContext, sr.StreamRunner, true)
_, err := s.SubmitStream(s.baseCtx, sr.user, sr.Channel, sr.Path, sr.Data, sr.PluginContext, sr.StreamRunner, true)
if err != nil {
// Log error but do not prevent execution of caller routine.
logger.Error("Error re-submitting stream", "path", sr.Path, "error", err)
@@ -301,6 +301,7 @@ func (s *Manager) runStream(ctx context.Context, cancelFn func(), sr streamReque
&backend.RunStreamRequest{
PluginContext: pluginCtx,
Path: sr.Path,
Data: sr.Data,
},
backend.NewStreamSender(&packetSender{channelLocalPublisher: s.channelSender, channel: sr.Channel}),
)
@@ -375,6 +376,7 @@ type streamRequest struct {
user *models.SignedInUser
PluginContext backend.PluginContext
StreamRunner StreamRunner
Data []byte
}
type submitRequest struct {
@@ -398,7 +400,7 @@ var errDatasourceNotFound = errors.New("datasource not found")
// SubmitStream submits stream handler in Manager to manage.
// The stream will be opened and kept till channel has active subscribers.
func (s *Manager) SubmitStream(ctx context.Context, user *models.SignedInUser, channel string, path string, pCtx backend.PluginContext, streamRunner StreamRunner, isResubmit bool) (*submitResult, error) {
func (s *Manager) SubmitStream(ctx context.Context, user *models.SignedInUser, channel string, path string, data []byte, pCtx backend.PluginContext, streamRunner StreamRunner, isResubmit bool) (*submitResult, error) {
if isResubmit {
// Resolve new plugin context as it could be modified since last call.
var datasourceUID string
@@ -423,6 +425,7 @@ func (s *Manager) SubmitStream(ctx context.Context, user *models.SignedInUser, c
Path: path,
PluginContext: pCtx,
StreamRunner: streamRunner,
Data: data,
},
}