Delete TaskQueueUtils (#1908)

For push queues, use CloudTasksUtils. Pull queues for now directly calls
the GAE task queue APIs. The usage of pull queues will be soon replaced.
This commit is contained in:
Lai Jiang 2023-01-19 14:45:18 -05:00 committed by GitHub
parent 925c9ba9e8
commit 630ae1f802
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 291 deletions

View file

@ -1,107 +0,0 @@
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.util;
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.TaskHandle;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.api.taskqueue.TransientFailureException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.flogger.FluentLogger;
import java.io.Serializable;
import java.util.List;
import javax.inject.Inject;
/**
* Utilities for dealing with App Engine task queues.
*
* <p>Use {@link CloudTasksUtils} to interact with push queues (Cloud Task queues). Pull queues will
* be implemented separately in SQL and you can continue using this class for that for now.
*/
@Deprecated
public class TaskQueueUtils implements Serializable {
private static final long serialVersionUID = 7893211200220508362L;
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Retrier retrier;
@Inject
public TaskQueueUtils(Retrier retrier) {
this.retrier = retrier;
}
@NonFinalForTesting
@VisibleForTesting
static int BATCH_SIZE = 1000;
/**
* The batch size to use for App Engine task queue operations.
*
* <p>Note that 1,000 is currently the maximum allowable batch size in App Engine.
*/
public static int getBatchSize() {
return BATCH_SIZE;
}
/**
* Adds a task to a App Engine task queue in a reliable manner.
*
* <p>This is the same as {@link Queue#add(TaskOptions)} except it'll automatically retry with
* exponential backoff if {@link TransientFailureException} is thrown.
*
* @throws TransientFailureException if retrying failed for the maximum period of time, or an
* {@link InterruptedException} told us to stop trying
* @return successfully enqueued task
*/
public TaskHandle enqueue(Queue queue, TaskOptions task) {
return enqueue(queue, ImmutableList.of(task)).get(0);
}
/**
* Adds tasks to an App Engine task queue in a reliable manner.
*
* <p>This is the same as {@link Queue#add(Iterable)} except it'll automatically retry with
* exponential backoff if {@link TransientFailureException} is thrown.
*
* @throws TransientFailureException if retrying failed for the maximum period of time, or an
* {@link InterruptedException} told us to stop trying
* @return successfully enqueued tasks
*/
public List<TaskHandle> enqueue(final Queue queue, final Iterable<TaskOptions> tasks) {
return retrier.callWithRetry(
() -> {
for (TaskOptions task : tasks) {
logger.atInfo().log(
"Enqueuing queue='%s' endpoint='%s'.", queue.getQueueName(), task.getUrl());
}
return queue.add(tasks);
},
TransientFailureException.class);
}
/** Deletes the specified tasks from the queue in batches, with retrying. */
public void deleteTasks(Queue queue, List<TaskHandle> tasks) {
Lists.partition(tasks, BATCH_SIZE)
.stream()
.forEach(
batch ->
retrier.callWithRetry(
() -> queue.deleteTask(batch), TransientFailureException.class));
}
}