Limpar tarefas de uma fila

Exemplo de limpeza de tarefas de uma fila para migrar do taskqueues.

Amostra de código

Java

Para saber como instalar e usar a biblioteca de cliente do Cloud Tasks, consulte Bibliotecas de cliente do Cloud Tasks.

import com.google.cloud.tasks.v2.CloudTasksClient;
import com.google.cloud.tasks.v2.QueueName;

public class PurgeQueue {
  public static void purgeQueue(String projectId, String locationId, String queueId)
      throws Exception {
    try (CloudTasksClient client = CloudTasksClient.create()) {
      // TODO(developer): Uncomment these lines and replace with your values.
      // String projectId = "your-project-id";
      // String locationId = "us-central1";
      // String queueId = "foo";

      // Construct the fully qualified queue name.
      String queueName = QueueName.of(projectId, locationId, queueId).toString();

      client.purgeQueue(queueName);
      System.out.println("Queue Purged.");
    }
  }
}

Python

Para saber como instalar e usar a biblioteca de cliente do Cloud Tasks, consulte Bibliotecas de cliente do Cloud Tasks.

client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'

queue_path = client.queue_path(project, location, queue)
response = client.purge_queue(name=queue_path)