-
Notifications
You must be signed in to change notification settings - Fork 496
Monitor ENF calculation more closely for better progress feedback (EXPOSUREAPP-2743) #1473
Conversation
…cluations. * Introduces new reactive data provider "HotData" that allows lazy init and safe updates.
… still calculating.
…r ENF Window Mode, which has no more "tokens".
… based on the `finishedAt` timestamp. Also improve test readability a bit and added more edge cases when checking timeouts.
In another PR we should consider replacing the timestamp on the risk card, which currently reflects the last time the download was finished, but it makes more sense if it's the timestamp of the newest tracked calculation (which would IMHO be the fix for #948). |
import timber.log.Timber | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
class HotDataFlow<T : Any>( |
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 PR also introduces a nice helper class dubbed HotDataFlow
.
It's a flowable that
- Does lazy init. The start value is provided via a suspending function that is only executed if someone subscribes
- Shares all updates between all subscribers as long as there is at least one subscriber.
- Allows threadsafe updates to it's contents as it only allows its data to be changed by giving it an "update function" that takes the current value and can return a new one.
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.
Turned out very nicely.
…ker if the list of key files is non-empty.
…transient fields. GSON sets it to false, and does not eval the properties to set them.
The chance for overlapping calculations is rare with batched key submission, and if gives us a lower chance of actually being affected by timeouts.
I've changed the |
You invited for feedback. First class. Nothing else to say. 👍 |
@d4rken as discussed, let's set the timeout to 15 minutes initially, should already be quite conservative. |
...ain/java/de/rki/coronawarnapp/nearby/modules/calculationtracker/CalculationTrackerStorage.kt
Outdated
Show resolved
Hide resolved
…n with Maximilian. In worst case scenarios no calculation exceeded 7 minutes.
…, overwrites the timeout.
Allows use to later set global settings (pretty print for testers?), or hook up custom serializers app-wide.
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
passed deep look & test. lgtm |
Why
We want to display better progress feedback, we want to know when the download is happening and when we are waiting for the ENF to check the keys.
The goal is to show two different progress types, this PR does not yet add that, but adds the necessary base classes. For now the
isRefreshing
state will be displayed on the risk card if either the transaction is on-going, or the ENF is still calculating.How
This PR adds the
CalculationTracker
, which is a set of classes that can track the ENF calcluations that happen outside of our app process.The idea is:
ACTION_EXPOSURE_STATE_UPDATED
andACTION_EXPOSURE_NOT_FOUND
To the rest of the app we expose a
CalculationTracker.calculations: Flow<Map<String, Calculation>>
:finishedAt
timestamp set by us, it's still calculating.ENFClient
which offers easier access withisCurrentlyCalculating(): Flow<Boolean>
latestFinishedCalculation(): Flow<Calculation?>
To notice any issues within the ENF that don't throw us an exception, there is a timeout checker running within the calculation tracker.
Every 5 minutes it will evaluate the
startedAt
timestamps of all known calculations. If it exceeds the timeout (currently 60 minutes, @mlenkeit thoughts on that?, might be a bit high), the calculation is considered "timed out", get the result type "TIMEOUT", and given the current time asfinishedAt
timestamp (which marks it as no longer "in calculation").The calculation data is persisted everytime there is an update to the data map. The class
CalculationTrackerStorage
loads and stores the map as serialized JSON file to our private app storage.Testing
CalculationTracker