Skip to content

Commit f57d46b

Browse files
committed
Integrate App Engine Task Queue API with Google Cloud Tasks.
This change introduces support for routing App Engine push queues to Google Cloud Tasks when the APPENGINE_USE_CLOUDTASK_PUSH_QUEUE environment variable is enabled. Key changes include: - Adding CloudTasksClientWrapper to handle task creation, deletion, purging, and statistics using the Cloud Tasks SDK and REST API. - Implementing transactional task queuing via a Datastore-backed buffer (_AE_PendingCloudTask) and a background sweeper (SweeperServlet and TaskProcessor) to guarantee delivery. - Introducing RequestCachingFilter to cache task request payloads and handle sweep triggers. - Updating QueueImpl to delegate push queue operations to the new Cloud Tasks integration. - Updating Maven and Bazel build files to include the required Google Cloud Tasks, GAX, and proto dependencies. PiperOrigin-RevId: 965724714 Change-Id: Idd794e9528d0f8918b03e5a7fbf7656f902e6124
1 parent 17bf221 commit f57d46b

19 files changed

Lines changed: 2770 additions & 63 deletions

File tree

api/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
<groupId>javax.servlet</groupId>
123123
<artifactId>javax.servlet-api</artifactId>
124124
</dependency>
125+
<dependency>
126+
<groupId>com.google.cloud</groupId>
127+
<artifactId>google-cloud-tasks</artifactId>
128+
</dependency>
125129
<dependency>
126130
<groupId>org.antlr</groupId>
127131
<artifactId>antlr-runtime</artifactId>

api/src/main/java/com/google/appengine/api/datastore/DatastoreApiHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public final class DatastoreApiHelper {
5656

5757
private DatastoreApiHelper() {}
5858

59+
/**
60+
* Registers a callback to be executed immediately after the specified transaction commits.
61+
* If the transaction is rolled back or fails to commit, the callback will not be invoked.
62+
*/
63+
public static void addPostCommitCallback(Transaction txn, Runnable callback) {
64+
if (txn instanceof TransactionImpl txnImpl && callback != null) {
65+
txnImpl.addPostCommitCallback(callback);
66+
}
67+
}
68+
5969
// Corresponds to _ToDatastoreError in datastore.py.
6070
// Keep in sync!
6171
public static RuntimeException translateError(ApiProxy.ApplicationException exception) {

api/src/main/java/com/google/appengine/api/datastore/TransactionImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ enum TransactionState {
8181

8282
TransactionState state = TransactionState.BEGUN;
8383

84+
private final List<Runnable> postCommitCallbacks = new java.util.concurrent.CopyOnWriteArrayList<>();
85+
86+
void addPostCommitCallback(Runnable callback) {
87+
if (callback != null) {
88+
postCommitCallbacks.add(callback);
89+
}
90+
}
91+
8492
/** A {@link PostOpFuture} implementation that runs both post put and post delete callbacks. */
8593
private class PostCommitFuture extends PostOpFuture<Void> {
8694
private final List<Entity> putEntities;
@@ -100,6 +108,13 @@ void executeCallbacks(Void ignoreMe) {
100108
DeleteContext deleteContext =
101109
new DeleteContext(TransactionImpl.this, TransactionImpl.this, deletedKeys);
102110
callbacks.executePostDeleteCallbacks(deleteContext);
111+
for (Runnable callback : postCommitCallbacks) {
112+
try {
113+
callback.run();
114+
} catch (Throwable t) {
115+
logger.log(Level.SEVERE, "Exception in post-commit callback: " + t.getMessage(), t);
116+
}
117+
}
103118
}
104119
}
105120

0 commit comments

Comments
 (0)