문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top