executeTask static method

Future<bool> executeTask(
  1. String taskId, [
  2. Map<String, dynamic> data = const {}
])

Executes a registered background task handler directly by taskId with optional data.

Returns the boolean status returned by the registered handler, or false if no handler exists or an error occurred.

Example:

final success = await BloomBackground.executeTask('syncTasks', {'scope': 'all'});

Implementation

static Future<bool> executeTask(String taskId, [Map<String, dynamic> data = const {}]) async {
  final handler = _registeredTasks[taskId];
  if (handler == null) {
    logger.warn('BloomBackground: No handler registered for background task "$taskId"');
    return false;
  }

  try {
    logger.info('BloomBackground: Executing task "$taskId"...');
    final result = await handler(data);
    logger.info('BloomBackground: Task "$taskId" completed with status: $result');
    return result;
  } catch (e, st) {
    logger.error('BloomBackground: Task "$taskId" threw an error: $e', e, st);
    return false;
  }
}