{@link Queue} is used to manage a task queue.
Implementations of this interface must be threadsafe.
Queues are transactional. If a datastore transaction is in progress when {@link #add()} or {@link #add(TaskOptions)} is invoked, the task will onlybe added to the queue if the datastore transaction successfully commits. If you want to add a task to a queue and have that operation succeed or fail independently of an existing datastore transaction you can invoke {@link #add(Transaction,TaskOptions)} with a {@code null} transactionargument. Note that while the addition of the task to the queue can participate in an existing transaction, the execution of the task cannot participate in this transaction. In other words, when the transaction commits you are guaranteed that your task will be added and run, not that your task executed successfully.
Queues may be configured in either push or pull mode, but they share the same interface. However, only tasks with {@link TaskOptions.Method#PULL} maybe added to pull queues. The tasks in push queues must be added with one of the other available methods.
Pull mode queues do not automatically deliver tasks to the application. The application is required to call {@link #leaseTasks(long,TimeUnit,long) leaseTasks} to acquire a lease onthe task and process them explicitly. Attempting to call {@link #leaseTasks(long,TimeUnit,long) leaseTasks} on a push queue causesa {@link InvalidQueueModeException} to be thrown. When the task processinghas finished processing a task that is leased, it should call {@link #deleteTask(String)}. If deleteTask is not called before the lease expires, the task will again be available for lease.
Queue mode can be switched between push and pull. When switching from push to pull, tasks will stay in the task queue and are available for lease, but url and headers information will be ignored when returning the tasks. When switching from pull to push, existing tasks will remain in the queue but will fail on auto-execution because they lack a url. If the queue mode is once again changed to pull, these tasks will eventually be available for lease.