MCPcopy
hub / github.com/wavetermdev/waveterm / ResyncController

Function ResyncController

pkg/blockcontroller/blockcontroller.go:151–285  ·  view source on GitHub ↗

Public API Functions

(ctx context.Context, tabId string, blockId string, rtOpts *waveobj.RuntimeOpts, force bool)

Source from the content-addressed store, hash-verified

149// Public API Functions
150
151func ResyncController(ctx context.Context, tabId string, blockId string, rtOpts *waveobj.RuntimeOpts, force bool) error {
152 if tabId == "" || blockId == "" {
153 return fmt.Errorf("invalid tabId or blockId passed to ResyncController")
154 }
155
156 mu := getBlockResyncMutex(blockId)
157 mu.Lock()
158 defer mu.Unlock()
159
160 blockData, err := wstore.DBMustGet[*waveobj.Block](ctx, blockId)
161 if err != nil {
162 return fmt.Errorf("error getting block: %w", err)
163 }
164
165 controllerName := blockData.Meta.GetString(waveobj.MetaKey_Controller, "")
166 connName := blockData.Meta.GetString(waveobj.MetaKey_Connection, "")
167
168 // Get existing controller
169 existing := getController(blockId)
170
171 // Check for connection change FIRST - always destroy on conn change
172 if existing != nil {
173 existingConnName := existing.GetConnName()
174 if existingConnName != connName {
175 log.Printf("stopping blockcontroller %s due to conn change (from %q to %q)\n", blockId, existingConnName, connName)
176 DestroyBlockController(blockId)
177 time.Sleep(100 * time.Millisecond)
178 existing = nil
179 }
180 }
181
182 // If no controller needed, stop existing if present
183 if controllerName == "" {
184 if existing != nil {
185 DestroyBlockController(blockId)
186 }
187 return nil
188 }
189
190 // Determine if we should use DurableShellController vs ShellController
191 shouldUseDurableShellController := controllerName == BlockController_Shell && jobcontroller.IsBlockIdTermDurable(blockId)
192
193 // Check if we need to morph controller type
194 if existing != nil {
195 needsReplace := false
196
197 switch existing.(type) {
198 case *ShellController:
199 if controllerName != BlockController_Shell && controllerName != BlockController_Cmd {
200 needsReplace = true
201 } else if shouldUseDurableShellController {
202 needsReplace = true
203 }
204 case *DurableShellController:
205 if !shouldUseDurableShellController {
206 needsReplace = true
207 }
208 case *TsunamiController:

Callers 1

Calls 15

GetRuntimeStatusMethod · 0.95
StartMethod · 0.95
DBMustGetFunction · 0.92
IsBlockIdTermDurableFunction · 0.92
IsLocalConnNameFunction · 0.92
getBlockResyncMutexFunction · 0.85
getControllerFunction · 0.85
DestroyBlockControllerFunction · 0.85
MakeShellControllerFunction · 0.85
registerControllerFunction · 0.85
MakeTsunamiControllerFunction · 0.85

Tested by

no test coverage detected