process method
Process the queue (replay mutations)
Implementation
Future<void> process() async {
if (_isProcessing || _queue.isEmpty || !ZenQueryCache.instance.isOnline) {
return;
}
_isProcessing = true;
ZenLogger.logDebug(
'Processing offline mutation queue (${_queue.length} jobs)...');
try {
// Process strictly in order (FIFO)
while (_queue.isNotEmpty && ZenQueryCache.instance.isOnline) {
final job = _queue.first;
try {
// Here we need a way to execute the job using the user's mutation logic.
// Since we serialized data but not functions, we need a registry.
// This is the hard part of offline mutations: "How to hydrate logic".
// For now, we will expose a generic "onReplay" callback registry.
await _executeJob(job);
remove(job.id); // Success! Remove from queue.
} catch (e) {
ZenLogger.logError('Failed to replay mutation ${job.id}', e);
// If deterministic error, remove? If network, stop processing?
// If network error, we stop processing and wait for next reconnect.
if (!ZenQueryCache.instance.isOnline) break;
// If typical error, maybe move to back or Dead Letter Queue?
// For simple implementation: Remove to prevent blocking?
// Or keep and retry later?
// Let's implement retry count limit.
remove(job.id);
}
}
} finally {
_isProcessing = false;
}
}