-
Notifications
You must be signed in to change notification settings - Fork 200
query: add OnMaxTries #308
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,10 @@ type Config struct { | |
// make this configurable to easily mock the worker used during tests. | ||
NewWorker func(Peer) Worker | ||
|
||
// OnMaxTries is function closure that's called on max retries on | ||
// workers. | ||
OnMaxTries func(string) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think we should instead use a stricter type here (net.Addr) and mention what is being passed to this call-back so that the caller doesnt have to go look at the code to figure out what is being passed to the call-back it is setting. The commit message isnt very accurate imo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's worth linking the PR that makes use of this new config option in the PR description so that reviewers can understand the context a bit more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Will address both points. |
||
|
||
// Ranking is used to rank the connected peers when determining who to | ||
// give work to. | ||
Ranking PeerRanking | ||
|
@@ -381,6 +385,10 @@ Loop: | |
log.Debugf("Canceled batch %v", | ||
batchNum) | ||
|
||
if w.cfg.OnMaxTries != nil { | ||
w.cfg.OnMaxTries(result.peer.Addr()) | ||
} | ||
|
||
continue Loop | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think this adds anything. This select is already covered in below and so if peer.OnDisconnect() triggers before the message is received on the msgChan, we will already catch the case below.
I think what you instead want is for
job.HandleResp
's function to know if it can exit or not.The idiomatic way of doing this would be to pass it a
ctx context.Context
which gets cancelled when the peer disconnects. An intermediate step can just be to pass it aquit chan struct{}
which you can derive from thepeer
sOnDisconnect
method and then listen on that in the HandleResp call-backThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason for adding this is because I saw that there are cases where
case resp := <- msgChan:
gets triggered first before the belowcase <-peer.OnDisconnect():
gets triggered.Yeah that would also solve the problem I was seeing.
That would be ok as well except now we force every implementation of
HandleResp
to handle the case wherequit chan struct{}
is passed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'll also add that I don't really have a preference on how that's handled so I'll push changes so that
HandleResp
takes aquti chan struct{}
as an argument.