Skip to content

Commit

Permalink
⚙️ split plugin connect func and assignation
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Dec 15, 2024
1 parent 8badda7 commit ceb2585
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions providers/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func (r *Runtime) AddConnectedProvider(c *ConnectedProvider) {
r.mu.Unlock()
}

func (r *Runtime) setProviderConnection(c *plugin.ConnectRes, err error) {
r.mu.Lock()
r.Provider.Connection = c
r.Provider.ConnectionError = err
r.mu.Unlock()
}

func (r *Runtime) addProvider(id string) (*ConnectedProvider, error) {
// TODO: we need to detect only the shared running providers
running, err := r.coordinator.GetRunningProvider(id, r.AutoUpdate)
Expand Down Expand Up @@ -239,11 +246,10 @@ func (r *Runtime) Connect(req *plugin.ConnectReq) error {

// }

r.mu.Lock()
r.Provider.Connection, r.Provider.ConnectionError = r.Provider.Instance.Plugin.Connect(req, &callbacks)
r.mu.Unlock()
if r.Provider.ConnectionError != nil {
return r.Provider.ConnectionError
conn, err := r.Provider.Instance.Plugin.Connect(req, &callbacks)
r.setProviderConnection(conn, err)
if err != nil {
return err
}

// TODO: This is a stopgap that detects if the connect call returned an asset
Expand All @@ -265,9 +271,10 @@ func (r *Runtime) Connect(req *plugin.ConnectReq) error {
if postProvider.ID != r.Provider.Instance.ID {
req.Asset = r.Provider.Connection.Asset
r.UseProvider(postProvider.ID)
r.Provider.Connection, r.Provider.ConnectionError = r.Provider.Instance.Plugin.Connect(req, &callbacks)
if r.Provider.ConnectionError != nil {
return r.Provider.ConnectionError
conn, err := r.Provider.Instance.Plugin.Connect(req, &callbacks)
r.setProviderConnection(conn, err)
if err != nil {
return err
}
}

Expand Down

0 comments on commit ceb2585

Please sign in to comment.