Skip to content

backoff: Make duration bounds customizable #975

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

Merged
merged 6 commits into from
Oct 8, 2024
Merged

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Oct 1, 2024

This will let us have some backoff loops that back off more patiently than others, e.g. because their work is happening in the background and isn't expected to be something the user is already waiting for.

In particular I plan to use this for backing off the fetch of server emoji data, for #669.

@gnprice gnprice added a-api Implementing specific parts of the Zulip server API maintainer review PR ready for review by Zulip maintainers labels Oct 1, 2024
@PIG208 PIG208 self-assigned this Oct 1, 2024
@chrisbobbe
Copy link
Collaborator

Ah I reviewed this before I noticed it was assigned to @PIG208. LGTM, but I'd be happy to wait for @PIG208's review if that's desired or @PIG208 if you've started yours already. :)

/// The actual duration will vary randomly up to this value; see [wait].
static const firstBound = Duration(milliseconds: 100);

/// The maximum bound on the duration of each wait, even after many waits.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Should we mention explicitly that this, and firstBound are upper bounds on the first line, respectively? I feel that these are the first reads for one when looking at the BackoffMachine interface.

@PIG208
Copy link
Member

PIG208 commented Oct 5, 2024

Sorry for the delay! Posted a comment. This LGTM overall.

This field is initialized but never looked at thereafter.
So we can just cut it.

It looks like it was never used in the previous history of this
file, nor in the history of the corresponding code in zulip-mobile.
Presumably it was left over from an earlier draft of that
zulip-mobile implementation.
This code was originally adapted from an implementation in JavaScript
(from zulip-mobile), and followed that implementation in representing
durations mostly as doubles in milliseconds.

Before making other changes here, and in particular exposing some
of these durations in the class's API, let's adapt it more fully to
Dart idioms and norms.
… body

The use of an expression body (with `=>`) in this situation is
forbidden in the upstream Flutter style guide:
  https://github.com/flutter/flutter/blob/e6c955416da/docs/contributing/Style-guide-for-Flutter-repo.md#consider-using--for-short-functions-and-methods
  https://github.com/flutter/flutter/blob/e6c955416da/docs/contributing/Style-guide-for-Flutter-repo.md#use--for-getters-and-callbacks-that-just-return-literals-or-switch-expressions

and I've regularly asked in code reviews to replace such things
with block bodies.

Apparently I hadn't yet absorbed that point, though, when I wrote
this code earlier this year.  And then just now I was rereading it
in order to refactor it, and found I had to visually scan the test's
code several times in order to see its overall structure.  Fix that.
Also make an editing pass over the [BackoffMachine.wait] doc.
@gnprice
Copy link
Member Author

gnprice commented Oct 8, 2024

Thanks for the reviews! Merging, with that tweak.

@gnprice gnprice merged commit 5e63b1d into zulip:main Oct 8, 2024
1 check passed
@gnprice gnprice deleted the pr-backoff branch October 8, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-api Implementing specific parts of the Zulip server API maintainer review PR ready for review by Zulip maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants