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

feat: 5405 - 3 queues for background tasks (fast, slow, long haul) #5743

Merged
merged 2 commits into from
Oct 27, 2024

Conversation

monsieurtanuki
Copy link
Contributor

What

  • Now we use 3 queues for the background tasks, for different purposes:
    • fast actions, like changing a product label
    • slow actions, like uploading a new photo
    • long haul actions, like refreshing the whole local database from the server
  • The 3 queues are run in parallel.
  • The main added value is that fast actions will be run earlier (and faster), as they won't have to wait for any slow or long haul action to finish. Particularly relevant with low connectivity.

Screenshots

Example of background tasks on an offline device (therefore everything fails):

  • a fast product edit
  • a price with proof upload
  • a product photo upload
  • a refresh of the whole local database
task page (top) task page (bottom)
Screenshot_20241026_152850 Screenshot_20241026_152856

Fixes bug(s)

Files

New file:

  • background_task_queue.dart: Queues for Background Tasks.

Impacted files:

  • background_task.dart: now we add tasks to a specific queue
  • background_task_add_other_price.dart: assigned to BackgroundTaskQueue.fast
  • background_task_add_price.dart: assigned to BackgroundTaskQueue.slow
  • background_task_badge.dart: minor refactoring
  • background_task_crop.dart: assigned to BackgroundTaskQueue.fast
  • background_task_details.dart: assigned to BackgroundTaskQueue.fast
  • background_task_download_products.dart: assigned to BackgroundTaskQueue.longHaul
  • background_task_full_refresh.dart: assigned to BackgroundTaskQueue.longHaul
  • background_task_hunger_games.dart: assigned to BackgroundTaskQueue.fast
  • background_task_image.dart: assigned to BackgroundTaskQueue.slow
  • background_task_language_refresh.dart: assigned to BackgroundTaskQueue.longHaul
  • background_task_manager.dart: now using new class BackgroundTaskQueue in order to use multiple queues
  • background_task_offline.dart: assigned to BackgroundTaskQueue.longHaul
  • background_task_refresh_later.dart: assigned to BackgroundTaskQueue.fast
  • background_task_top_barcodes.dart: assigned to BackgroundTaskQueue.longHaul
  • background_task_unselect.dart: assigned to BackgroundTaskQueue.fast
  • dao_string_list.dart: added 2 queues
  • local_database.dart: now running all queues
  • local_database_mock.dart: minor refactoring
  • offline_tasks_page.dart: now taking queues into account
  • up_to_date_mixin.dart: now running all queues
  • user_preferences_page.dart: now running all queues

New file:
* `background_task_queue.dart`: Queues for Background Tasks.

Impacted files:
* `background_task.dart`: now we add tasks to a specific queue
* `background_task_add_other_price.dart`: assigned to `BackgroundTaskQueue.fast`
* `background_task_add_price.dart`: assigned to `BackgroundTaskQueue.slow`
* `background_task_badge.dart`: minor refactoring
* `background_task_crop.dart`: assigned to `BackgroundTaskQueue.fast`
* `background_task_details.dart`: assigned to `BackgroundTaskQueue.fast`
* `background_task_download_products.dart`: assigned to `BackgroundTaskQueue.longHaul`
* `background_task_full_refresh.dart`: assigned to `BackgroundTaskQueue.longHaul`
* `background_task_hunger_games.dart`: assigned to `BackgroundTaskQueue.fast`
* `background_task_image.dart`: assigned to `BackgroundTaskQueue.slow`
* `background_task_language_refresh.dart`: assigned to `BackgroundTaskQueue.longHaul`
* `background_task_manager.dart`: now using new class `BackgroundTaskQueue` in order to use multiple queues
* `background_task_offline.dart`: assigned to `BackgroundTaskQueue.longHaul`
* `background_task_refresh_later.dart`: assigned to `BackgroundTaskQueue.fast`
* `background_task_top_barcodes.dart`: assigned to `BackgroundTaskQueue.longHaul`
* `background_task_unselect.dart`: assigned to `BackgroundTaskQueue.fast`
* `dao_string_list.dart`: added 2 queues
* `local_database.dart`: now running all queues
* `local_database_mock.dart`: minor refactoring
* `offline_tasks_page.dart`: now taking queues into account
* `up_to_date_mixin.dart`: now running all queues
* `user_preferences_page.dart`: now running all queues
@codecov-commenter
Copy link

codecov-commenter commented Oct 26, 2024

Codecov Report

Attention: Patch coverage is 35.00000% with 39 lines in your changes missing coverage. Please review.

Project coverage is 7.00%. Comparing base (4d9c7fc) to head (5abcebe).
Report is 395 commits behind head on develop.

Files with missing lines Patch % Lines
...kages/smooth_app/lib/pages/offline_tasks_page.dart 0.00% 13 Missing ⚠️
...ooth_app/lib/background/background_task_badge.dart 0.00% 4 Missing ⚠️
...th_app/lib/background/background_task_manager.dart 83.33% 4 Missing ⚠️
...ckages/smooth_app/lib/database/local_database.dart 0.00% 3 Missing ⚠️
...ges/smooth_app/lib/background/background_task.dart 0.00% 2 Missing ⚠️
...ib/background/background_task_add_other_price.dart 0.00% 1 Missing ⚠️
..._app/lib/background/background_task_add_price.dart 0.00% 1 Missing ⚠️
...mooth_app/lib/background/background_task_crop.dart 0.00% 1 Missing ⚠️
.../background/background_task_download_products.dart 0.00% 1 Missing ⚠️
...p/lib/background/background_task_full_refresh.dart 0.00% 1 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #5743      +/-   ##
==========================================
- Coverage     9.54%   7.00%   -2.55%     
==========================================
  Files          325     407      +82     
  Lines        16411   21793    +5382     
==========================================
- Hits          1567    1527      -40     
- Misses       14844   20266    +5422     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@teolemon teolemon left a comment

Choose a reason for hiding this comment

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

  • Is the Add Price missing a barcode, or are those multiple prices ? (For better task consistency)
  • Would a "Upload now" button be useful ? Perhaps on the edit page itself as a simplified thing ? "2 images and 1 edit pending upload. Attempt immediate upload" ?

@monsieurtanuki
Copy link
Contributor Author

  • Is the Add Price missing a barcode, or are those multiple prices ? (For better task consistency)

"Add price" task means multiple product prices and proof image upload.
"Add other price" task means multiple product prices using an existing proof (=> no upload).

  • Would a "Upload now" button be useful ? Perhaps on the edit page itself as a simplified thing ? "2 images and 1 edit pending upload. Attempt immediate upload" ?

The current PR isn't about UI/UX. Can be done in a next PR.

@monsieurtanuki monsieurtanuki merged commit 69bb171 into openfoodfacts:develop Oct 27, 2024
6 checks passed
@monsieurtanuki
Copy link
Contributor Author

Thank you @teolemon for your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Enhancement] Improving background tasks
3 participants