getPending method

  1. @override
Future<List<SyncEntry>> getPending({
  1. int limit = 50,
  2. DateTime? now,
})
override

Get pending (un-synced) entries, oldest first. If now is provided, only returns entries where nextRetryAt is null or <= now.

Implementation

@override
Future<List<SyncEntry>> getPending({int limit = 50, DateTime? now}) async {
  final String sql;
  final List<Variable> variables;

  if (now != null) {
    sql = 'SELECT * FROM dynos_sync_queue WHERE synced_at IS NULL '
        'AND (next_retry_at IS NULL OR next_retry_at <= ?) '
        'ORDER BY created_at ASC LIMIT ?';
    variables = [
      Variable.withInt(now.millisecondsSinceEpoch),
      Variable.withInt(limit),
    ];
  } else {
    sql = 'SELECT * FROM dynos_sync_queue WHERE synced_at IS NULL '
        'ORDER BY created_at ASC LIMIT ?';
    variables = [Variable.withInt(limit)];
  }

  final rows = await _db.customSelect(sql, variables: variables).get();
  return rows.map(_mapRow).toList();
}