Question

I'd like to

  1. Start a Google appengine transaction
  2. Create and enqueue a task onto a queue (outside any transaction)
  3. Close the transaction by committing or discarding it

How do I do #2 outside the transaction in Java?

Motivation is mostly to avoid the 5-task limit.

Was it helpful?

Solution

You can use a null transaction argument to the following variant of the Queue.add method.

add(Transaction txn, TaskOptions taskOptions)

This is explained at the top of the Queue interface documentation. It will make adding the tasks independent to the success or failure of an active transaction.

However, if you really don't care about queueing the tasks even if the transaction fails, you could create the TaskOptions objects in a list within the transaction and then enqueue them in one call after the transaction completes. That way, you will not incur the latency costs of adding to the queue inside your transaction.

OTHER TIPS

One option could be:

  1. Append to a single task data payload within your transaction. Each additional chunk of data would be suitable for its own task.
  2. Enqueue one task with your aggregated task payload just before the transaction is committed.
  3. The one transactional task executes. It breaks the data payload up into separate new tasks which you enqueue.
  4. Each enqueud task executes.

Suitable? (You would need to verify that a transactional task can itself enqueue tasks which are not transactional.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top