Skip to content

Commit

Permalink
fix: test notify
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Sep 20, 2024
1 parent 0597b79 commit 52aa741
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
12 changes: 12 additions & 0 deletions app/sephirah/internal/biz/biznetzach/netzach.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ func (n *Netzach) CreateNotifyFlow(ctx context.Context, flow *modelnetzach.Notif
if err != nil {
return 0, pb.ErrorErrorReasonUnspecified("%s", err.Error())
}
if len(flow.Sources) > 0 {
for _, source := range flow.Sources {
err = n.notifySourceCache.Delete(ctx, source.SourceID)
if err != nil {
logger.Errorf("failed to delete cache %s", err.Error())
}
}
}
err = n.notifyFlowCache.Delete(ctx, flow.ID)
if err != nil {
logger.Errorf("failed to delete cache %s", err.Error())
}
return flow.ID, nil
}

Expand Down
3 changes: 1 addition & 2 deletions app/sephirah/internal/data/netzach.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifyflow"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifyflowsource"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifyflowtarget"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifysource"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/notifytarget"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/systemnotification"
"github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/user"
Expand Down Expand Up @@ -264,7 +263,7 @@ func (n *netzachRepo) GetNotifyFlow(ctx context.Context, id model.InternalID) (*

func (n *netzachRepo) GetNotifyFlowIDsWithFeed(ctx context.Context, id model.InternalID) ([]model.InternalID, error) {
ids, err := n.data.db.NotifyFlow.Query().Where(
notifyflow.HasNotifySourceWith(notifysource.FeedConfigIDEQ(id)),
notifyflow.HasNotifyFlowSourceWith(notifyflowsource.NotifySourceIDEQ(id)),
).IDs(ctx)
if err != nil {
return nil, err
Expand Down
35 changes: 21 additions & 14 deletions app/sephirah/internal/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,28 +348,35 @@ func (s *Supervisor) updateControllers(
ctl.ConnectionStatus = modelsupervisor.PorterConnectionStatusActive
ctl.LastHeartbeat = now
}
if resp == nil || resp.GetEnablesSummary() == nil {
if ctl.ConnectionStatus == modelsupervisor.PorterConnectionStatusActive && resp == nil {
return nil
}
var reQueueContext []model.InternalID
if ctl.ConnectionStatus == modelsupervisor.PorterConnectionStatusActive {
onlyLast, _ := libtype.DiffSlices(
ctl.LastEnabledContext,
converter.ToBizInternalIDList(resp.GetEnablesSummary().GetContextIds()),
)
reQueueContext = onlyLast
ctl.LastEnabledContext = converter.ToBizInternalIDList(resp.GetEnablesSummary().GetContextIds())
for _, id := range onlyLast {
ic, ok := s.instanceContextController.Load(id)
if !ok {
continue
}
ic.HandleStatus = modelsupervisor.PorterContextHandleStatusQueueing
ic.HandleStatusMessage = ""
ic.HandlerAddress = ""
s.instanceContextController.Store(id, ic)
err := s.QueuePorterContext(ctx, ic.PorterContext)
if err != nil {
return err
}
} else {
reQueueContext = ctl.LastEnabledContext
if ctl.ConnectionStatus == modelsupervisor.PorterConnectionStatusDowngraded {
ctl.LastEnabledContext = nil
}
}
for _, id := range reQueueContext {
ic, ok := s.instanceContextController.Load(id)
if !ok {
continue
}
ic.HandleStatus = modelsupervisor.PorterContextHandleStatusQueueing
ic.HandleStatusMessage = ""
ic.HandlerAddress = ""
s.instanceContextController.Store(id, ic)
err := s.QueuePorterContext(ctx, ic.PorterContext)
if err != nil {
return err
}
}
return nil
Expand Down

0 comments on commit 52aa741

Please sign in to comment.