incrementRetryAttempt method

Future<void> incrementRetryAttempt(
  1. int id,
  2. int currentAttempts,
  3. int maxRetries
)

Increments retry count and schedules next attempt using exponential backoff. Deletes the record if currentAttempts + 1 >= maxRetries.

Implementation

Future<void> incrementRetryAttempt(
  int id,
  int currentAttempts,
  int maxRetries,
) async {
  final newAttempts = currentAttempts + 1;
  if (newAttempts >= maxRetries) {
    await deletePendingUpload(id);
    return;
  }
  final delayMinutes = math.min(60, math.pow(2, newAttempts).toInt());
  final nextRetryAt = DateTime.now().add(Duration(minutes: delayMinutes));
  final db = await database;
  await db.update(
    'pending_uploads',
    {
      'attempts': newAttempts,
      'next_retry_at': nextRetryAt.toIso8601String(),
    },
    where: 'id = ?',
    whereArgs: [id],
  );
}