enqueueImmediateSyncTask method

Future<void> enqueueImmediateSyncTask(
  1. SyncOperation operation,
  2. T item,
  3. String idempotencyKey,
  4. Map<String, String>? headers,
  5. Map<String, dynamic>? extra,
)

Creates and enqueues a NetworkTask for immediate sync execution.

This method is used by save operations to perform immediate background sync while also maintaining the sync queue entry for retry capability.

operation The type of sync operation to enqueue (create, update, delete). item The model instance to sync. idempotencyKey A unique key to ensure idempotent task execution. headers Optional headers to include in the API request. extra Optional extra data to include in the API request.

Implementation

Future<void> enqueueImmediateSyncTask(
  SyncOperation operation,
  T item,
  String idempotencyKey,
  Map<String, String>? headers,
  Map<String, dynamic>? extra,
) async {
  final syncTask = NetworkTask<void>(
    exec: () => executeSyncOperation(operation, item, headers, extra),
    idempotencyKey: idempotencyKey,
    operation: operation,
    modelType: T.toString(),
    modelId: item.id,
    taskName: 'BackgroundSync-${T.toString()}-${item.id}',
  );

  await queueManager.enqueueTask(syncTask, queueType: QueueType.background);
}