Public API Functions
(ctx context.Context, tabId string, blockId string, rtOpts *waveobj.RuntimeOpts, force bool)
| 149 | // Public API Functions |
| 150 | |
| 151 | func 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: |
no test coverage detected