Files
smooth-app/packages/smooth_app/lib/background/background_task_queue.dart
monsieurtanuki 69bb171a20 feat: 5405 - 3 queues for background tasks (fast, slow, long haul) (#5743)
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
2024-10-27 13:06:29 +01:00

57 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:smooth_app/database/dao_string_list.dart';
/// Queues for Background Tasks.
enum BackgroundTaskQueue {
fast(
tagLastStartTimestamp: 'taskLastStartTimestamp',
tagLastStopTimestamp: 'taskLastStopTimestamp',
tagTaskQueue: DaoStringList.keyTasksFast,
iconData: Icons.bolt,
aLongEnoughTimeInMilliseconds: 20 * 60 * 1000,
minimumDurationBetweenRuns: 5 * 1000,
),
slow(
tagLastStartTimestamp: 'taskLastStartTimestampSlow',
tagLastStopTimestamp: 'taskLastStopTimestampSlow',
tagTaskQueue: DaoStringList.keyTasksSlow,
iconData: Icons.upload,
aLongEnoughTimeInMilliseconds: 60 * 60 * 1000,
minimumDurationBetweenRuns: 5 * 1000,
),
longHaul(
tagLastStartTimestamp: 'taskLastStartTimestampLongHaul',
tagLastStopTimestamp: 'taskLastStopTimestampLongHaul',
tagTaskQueue: DaoStringList.keyTasksLongHaul,
iconData: Icons.download,
aLongEnoughTimeInMilliseconds: 60 * 60 * 1000,
minimumDurationBetweenRuns: 60 * 1000,
);
const BackgroundTaskQueue({
required this.tagLastStartTimestamp,
required this.tagLastStopTimestamp,
required this.tagTaskQueue,
required this.iconData,
required this.aLongEnoughTimeInMilliseconds,
required this.minimumDurationBetweenRuns,
});
/// [DaoInt] key we use to store the latest start timestamp.
final String tagLastStartTimestamp;
/// [DaoInt] key we use to store the latest stop timestamp.
final String tagLastStopTimestamp;
/// [DaoStringList] key we use to store the task queue.
final String tagTaskQueue;
/// Duration in millis after which we can imagine the previous run failed.
final int aLongEnoughTimeInMilliseconds;
/// Minimum duration in millis between each run.
final int minimumDurationBetweenRuns;
final IconData iconData;
}