layer1: add namespace remove dispatch step 33
This commit is contained in:
@@ -57,6 +57,7 @@ type NamespaceManager interface {
|
||||
SnapshotSubscribers() []string
|
||||
Upsert(event NamespaceEvent) NamespaceRecord
|
||||
DispatchAdd(ctx context.Context, namespace string) (NamespaceRecord, bool, error)
|
||||
DispatchRemove(ctx context.Context, namespace string) (NamespaceRecord, bool, error)
|
||||
DispatchResync(ctx context.Context, namespace string) (NamespaceRecord, bool, error)
|
||||
MarkPartState(namespace string, part string, state NamespacePartState) (NamespaceRecord, bool)
|
||||
MarkPartRegistering(namespace string, part string) (NamespaceRecord, bool)
|
||||
@@ -250,6 +251,30 @@ func (m *inMemoryNamespaceManager) DispatchAdd(ctx context.Context, namespace st
|
||||
})
|
||||
}
|
||||
|
||||
func (m *inMemoryNamespaceManager) DispatchRemove(ctx context.Context, namespace string) (NamespaceRecord, bool, error) {
|
||||
record, ok := m.Get(namespace)
|
||||
if !ok {
|
||||
return NamespaceRecord{}, false, nil
|
||||
}
|
||||
|
||||
var firstErr error
|
||||
for _, subscriber := range m.snapshotSubscriberObjects() {
|
||||
err := subscriber.OnNamespaceRemove(ctx, record)
|
||||
if err != nil && firstErr == nil {
|
||||
firstErr = err
|
||||
}
|
||||
}
|
||||
|
||||
removedRecord := m.Upsert(NamespaceEvent{
|
||||
Type: NamespaceEventRemove,
|
||||
Name: record.Name,
|
||||
Labels: record.Labels,
|
||||
Source: record.Source,
|
||||
ObservedAt: time.Now().UTC(),
|
||||
})
|
||||
return removedRecord, true, firstErr
|
||||
}
|
||||
|
||||
func (m *inMemoryNamespaceManager) DispatchResync(ctx context.Context, namespace string) (NamespaceRecord, bool, error) {
|
||||
return m.dispatch(ctx, namespace, func(subscriber NamespaceSubscriber, record NamespaceRecord) error {
|
||||
return subscriber.OnNamespaceResync(ctx, record)
|
||||
|
||||
Reference in New Issue
Block a user