delete method

Future<void> delete(
  1. String id
)

Deletes a task from the queue by its id.

A task can only be deleted if it hasn't been executed yet. If the task doesn't exist, this method completes successfully without error.

Example:

await queue.delete('unique-task-id');

Throws FirebaseFunctionsAdminException if the request fails.

Implementation

Future<void> delete(String id) async {
  try {
    final currentScope = _scope;
    if (currentScope is! _ExtensionOrKitFunctionScope) {
      await _requestHandler.delete(id, _functionName, currentScope);
      return;
    }

    try {
      await _requestHandler.delete(id, _functionName, currentScope);
    } on FirebaseFunctionsAdminException catch (err) {
      if (err.errorCode != FunctionsClientErrorCode.notFound) {
        rethrow;
      }
      // Not found, try fallback to kit scope.
      final tempKitScope = _KitFunctionScope(currentScope.instance);
      await _requestHandler.delete(id, _functionName, tempKitScope);
      // Only upgrade the stateful scope to kit if the retry request succeeds
      _scope = tempKitScope;
      _logFallbackWarning(_functionName, currentScope.instance);
    }
  } on FirebaseFunctionsAdminException catch (err) {
    if (err.errorCode != FunctionsClientErrorCode.notFound) {
      rethrow;
    }
    // Swallow notFound errors as delete is idempotent.
  }
}