MCPcopy Create free account
hub / github.com/cloudbase/garm / DeleteInstanceByName

Method DeleteInstanceByName

database/sql/instances.go:213–253  ·  view source on GitHub ↗
(ctx context.Context, instanceName string)

Source from the content-addressed store, hash-verified

211}
212
213func (s *sqlDatabase) DeleteInstanceByName(ctx context.Context, instanceName string) error {
214 instance, err := s.getInstance(ctx, s.conn, instanceName, "Pool", "ScaleSet")
215 if err != nil {
216 if errors.Is(err, runnerErrors.ErrNotFound) {
217 return nil
218 }
219 return fmt.Errorf("error deleting instance: %w", err)
220 }
221
222 defer func() {
223 if err == nil {
224 var providerID string
225 if instance.ProviderID != nil {
226 providerID = *instance.ProviderID
227 }
228 payload := params.Instance{
229 ID: instance.ID.String(),
230 Name: instance.Name,
231 ProviderID: providerID,
232 AgentID: instance.AgentID,
233 }
234 if instance.PoolID != nil {
235 payload.PoolID = instance.PoolID.String()
236 }
237 if instance.ScaleSetFkID != nil {
238 payload.ScaleSetID = *instance.ScaleSetFkID
239 }
240 if notifyErr := s.sendNotify(common.InstanceEntityType, common.DeleteOperation, payload); notifyErr != nil {
241 slog.With(slog.Any("error", notifyErr)).Error("failed to send notify")
242 }
243 }
244 }()
245
246 if q := s.conn.Unscoped().Delete(&instance); q.Error != nil {
247 if errors.Is(q.Error, gorm.ErrRecordNotFound) {
248 return nil
249 }
250 return fmt.Errorf("error deleting instance: %w", q.Error)
251 }
252 return nil
253}
254
255func (s *sqlDatabase) AddInstanceEvent(ctx context.Context, instanceName string, event params.EventType, eventLevel params.EventLevel, statusMessage string) error {
256 instance, err := s.getInstance(ctx, s.conn, instanceName)

Callers

nothing calls this directly

Calls 5

getInstanceMethod · 0.95
sendNotifyMethod · 0.95
DeleteMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected