* feat(backend): try a new approach for logs formatting (http) * feat(backend): added logger module * feat(backend): added project/session info to /i endpoint * feat(backend): found a solution for correct caller information * feat(backend): finished logs for http handlers * feat(backend): finished logs for mobile http handlers * feat(backend): finished ender * feat(backend): finished assets * feat(backend): finished heuristics * feat(backend): finished image-storage * feat(backend): finished sink * feat(backend): finished storage * feat(backend): formatted logs in all services * feat(backend): finished foss part * feat(backend): added missed foss part * feat(backend): fixed panic in memory manager and sink service * feat(backend): connectors
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package integrations
|
|
|
|
import (
|
|
"context"
|
|
"openreplay/backend/pkg/integrations/clients"
|
|
"openreplay/backend/pkg/integrations/model"
|
|
"openreplay/backend/pkg/logger"
|
|
)
|
|
|
|
type Manager struct {
|
|
log logger.Logger
|
|
clientMap clients.ClientMap
|
|
Events chan *clients.SessionErrorEvent
|
|
Errors chan error
|
|
RequestDataUpdates chan model.Integration // not pointer because it could change in other thread
|
|
}
|
|
|
|
func NewManager(log logger.Logger) *Manager {
|
|
return &Manager{
|
|
log: log,
|
|
clientMap: make(clients.ClientMap),
|
|
RequestDataUpdates: make(chan model.Integration, 100),
|
|
Events: make(chan *clients.SessionErrorEvent, 100),
|
|
Errors: make(chan error, 100),
|
|
}
|
|
}
|
|
|
|
func (m *Manager) Update(i *model.Integration) (err error) {
|
|
m.log.Info(context.Background(), "Integration initialization: %v\n", *i)
|
|
key := i.GetKey()
|
|
if i.Options == nil {
|
|
delete(m.clientMap, key)
|
|
return nil
|
|
}
|
|
c, exists := m.clientMap[key]
|
|
if !exists {
|
|
c, err = clients.NewClient(i, m.RequestDataUpdates, m.Events, m.Errors)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.clientMap[key] = c
|
|
}
|
|
return c.Update(i)
|
|
}
|
|
|
|
func (m *Manager) RequestAll() {
|
|
m.log.Info(context.Background(), "Requesting all...")
|
|
for _, c := range m.clientMap {
|
|
go c.Request()
|
|
}
|
|
}
|