(ctx context.Context, instanceName string)
| 211 | } |
| 212 | |
| 213 | func (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 | |
| 255 | func (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) |
nothing calls this directly
no test coverage detected