delete method

Future<void> delete(
  1. String id,
  2. String functionName,
  3. String? extensionId
)

Deletes a task from the specified function's queue.

Implementation

Future<void> delete(
  String id,
  String functionName,
  String? extensionId,
) async {
  validateNonEmptyString(functionName, 'functionName');
  validateNonEmptyString(id, 'id');

  if (!isValidTaskId(id)) {
    throw FirebaseFunctionsAdminException(
      FunctionsClientErrorCode.invalidArgument,
      'id can contain only letters ([A-Za-z]), numbers ([0-9]), '
      'hyphens (-), or underscores (_). The maximum length is 500 characters.',
    );
  }

  // Parse the function name
  final resources = _parseResourceName(functionName, 'functions');

  return _httpClient.cloudTasks((api, projectId) async {
    // Fill in missing resource components
    resources.projectId ??= projectId;
    resources.locationId ??= _defaultLocation;

    validateNonEmptyString(resources.resourceId, 'resourceId');

    // Apply extension ID prefix if provided
    var queueId = resources.resourceId;
    if (extensionId != null && extensionId.isNotEmpty) {
      queueId = 'ext-$extensionId-$queueId';
    }

    // Build the full task name
    final taskName = _httpClient.buildTaskName(
      projectId: resources.projectId!,
      locationId: resources.locationId!,
      queueId: queueId,
      taskId: id,
    );

    try {
      await api.projects.locations.queues.tasks.delete(taskName);
    } on tasks2.DetailedApiRequestError catch (error) {
      // If the task doesn't exist (404), ignore the error
      if (error.status == 404) {
        return;
      }
      rethrow; // Will be caught by _functionsGuard
    }
  });
}