-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
add Background Fetch method #5104
Conversation
maybe the question from deltachat/deltachat-ios#2017 (comment) is better places here, as more related to core than UI:
|
I answered over at deltachat/deltachat-ios#2017 (comment):
|
d416909
to
aa49d53
Compare
5380c6b
to
df7b5c5
Compare
one question: |
yes, that's the purpose of this event. |
f0e5ced
to
3e3a335
Compare
deltachat-jsonrpc/src/api.rs
Outdated
/// The `AccountsBackgroundFetchDone` event is emitted at the end, | ||
/// process all events until you get this one and you can safely return to the background | ||
/// without forgeting to create notifications caused by timing race conditions. | ||
async fn background_fetch_for_all_accounts(&self, timeout_in_seconds: f64) -> Result<()> { |
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.
better use the same, consistent method names as in ffi:
async fn background_fetch_for_all_accounts(&self, timeout_in_seconds: f64) -> Result<()> { | |
async fn accounts_background_fetch(&self, timeout_in_seconds: f64) -> Result<()> { |
(i see that the the "for_all_accounts" suffix is already in use, however, it is a little cumbersome wording and maybe not worth to be set in stone further)
|
||
/// Tells that the Background fetch was completed (or timed out). | ||
/// This event acts as a marker, when you reach this event you can be sure | ||
/// that all events emitted during the background fetch were processed. |
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.
nice explanation!
src/accounts.rs
Outdated
/// Performs a background fetch for all accounts in parallel. | ||
/// | ||
/// If you need a timeout, then use [Accounts::background_fetch_with_timeout] instead. | ||
/// | ||
/// The `AccountsBackgroundFetchDone` event is emitted at the end, | ||
/// process all events until you get this one and you can safely return to the background | ||
/// without forgeting to create notifications caused by timing race conditions. | ||
pub async fn background_fetch(&self) { |
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.
this function seems not to be needed as public; and making it public overcomplicates things:
apart from documentation and maintainance effort, eg. the AccountsBackgroundFetchDone
event seems to be emitted twice (background_fetch_with_timeout
calls background_fetch()
and both emit AccountsBackgroundFetchDone
at the end)
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 See the following possibilities:
- A. only emit the event in
background_fetch_with_timeout
- B. conditionally emit the event in
background_fetch_with_timeout
only on timeout - C. merge both functions into one (require to have a timeout)
- D. same as C, but keep it in two functions, making the
background_fetch
private / internal
As this is about networking, and it is in the nature of networking to be flaky, I'd say there is no really a use case for calling the background fetch without a timeout, so I think we should go for C (or D if we think we will find a use case for reusing the function in the future).
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.
yip, let's go for C. we currently do no need the case of "no timeout" and this is also not forseeable. yagni :)
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 pushed a commit to fix this (D variant).
maybe @link2xt can have a final look at the pr as well, also wrt future maintenance, he's most involved in. to sum up, the idea of the PR is to make things more reliable than the old call to the new approach of this PR is a dedicated currently, both approaches are for iOS mainly, but that may change in future. UI-wise it is a very easy replacement, most load is in core :) |
8b469e3
to
9862b4f
Compare
I have rebased and pushed one commit on top to fix the test with a note why |
There is a test after fixing it once, but the need to understand the whole "all_work_done" and how it is used by iOS when you just want to change connectivity is not nice, better have connectivity view as something user-visible but not machine-readable. |
It is not only about an easier more direct api, it is also to give us full control in core about what we do and also doing less work than with the normal imap loop. It is kinda like what |
one idea/question that came up while i explained the PR to @hpk42 : the initial idea of having a blocking call is a bit faded out by the need to wait for the event DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE in UI. things would be easier in UI and more under control of core, if that is not needed. also, as dc_background_fetch() will probably also become handy on android at some point. so question is: what would be the effort if core waits at the end of we should at least consider this question, might be it is far too much effort to do that in core and the UI way is much easier. |
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.
fine for me :)
EDIT: i just restarted the failing test to see if it is "real" :)
Failing test is #5201 |
also unify the error handling for the cases where it can go wrong.
Co-authored-by: link2xt <link2xt@testrun.org>
This may happen if Sent folder does not exist but configuration option to watch it is enabled.
Co-authored-by: bjoern <r10s@b44t.com>
Otherwise if there is a timeout, UI will wait for DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE forever.
80d47b2
to
fa5c6ad
Compare
background_fetch_for_all_accounts
dc_accounts_background_fetch_with_timeout
closes #4420
Todo:
BackgroundFetchCompletedForAllAccounts
event as described in use core background fetch deltachat-ios#2017 (comment) (basically to provide a way to know when all events caused by the background fetch were processed)