Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] StatusChanged for core and js subscriptions #1570

Merged
merged 5 commits into from
Mar 11, 2024
Merged

Conversation

piotrpio
Copy link
Collaborator

Signed-off-by: Piotr Piotrowski piotr@synadia.com

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
nats.go Outdated
return drainCh
}

func (s *drainStatus) PendingMsgs() int {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can get this from sub.Pending() already for both PendingMsgs abd PendingBytes, maybe not needed?

nats.go Outdated
}
}

func (s *drainStatus) Draining() bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be part of subscription state instead sub.IsDraining maybe? like the sub companion for nc.IsDraining

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I suppose getting rid of DrainStatus() method and hanging everything off from Subscription is a good call. At first I had a different idea around structuring it and left the API it as it was. I'll change that.

nats.go Outdated
defer s.sub.mu.Unlock()
if s.sub.drainingComplete == nil {
drainCh = make(chan struct{})
s.sub.drainingComplete = drainCh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drainingComplete maybe too long, could be instead sub.drainCh like here or sub.dch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drainCh sounds good, I'll change it. dch is a bit too ambiguous for my liking.

}
time.Sleep(100 * time.Millisecond)
sub.Drain()
ds := sub.DrainStatus()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe later can have some helper build on top like sub.WaitDrained(ctx) error that waits for drain to complete or timeout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea. Not sure I want to add it in this PR though, it's easy enough to implement it yourself and I want to be careful about adding public APIs.

In the future though, that might be useful.

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I don't like the DrainingComplete behavior.

nats.go Outdated Show resolved Hide resolved
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio
Copy link
Collaborator Author

piotrpio commented Mar 1, 2024

I changed the approach a bit and instead of a method for listening for draining completion on subscription I've added a StatusChanged method (similar to what we already have on `Conn).

This allows getting notifications on several events on a subscription - sub active, draining, closed and slow consumer for now.

This matches what we have for conn and seems to be a more robust solution than only checking drain status.

@Jarema @wallyqs can you take a look and give me your thoughts?

@piotrpio piotrpio changed the title [ADDED] DrainStatus for core and js subscriptions [ADDED] StatusChanged for core and js subscriptions Mar 1, 2024
@Jarema
Copy link
Member

Jarema commented Mar 4, 2024

I really like this approach, as it looks way more consistent with how we handle those events.
It looks like a nice feature, instead of a hack to get out the desired behavior.
I will review it in depth today.

nats.go Show resolved Hide resolved
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio piotrpio marked this pull request as ready for review March 11, 2024 10:30
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@piotrpio piotrpio merged commit 92c4a99 into main Mar 11, 2024
2 checks passed
@piotrpio piotrpio deleted the blocking-drain branch March 11, 2024 12:57
@piotrpio piotrpio mentioned this pull request Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants