我阅读了谷歌文档,但只有关于非延迟任务的说法。在那里我们创建带有参数的 xml 文件,并可以指定重试次数。
但我使用延迟任务:
public static class ExpensiveOperation implements DeferredTask
{
@Override
public void run()
{
System.out.println("Doing an expensive operation...");
// expensive operation to be backgrounded goes here
}
}
并以这种方式创建它:
Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withPayload(new ExpensiveOperation(/*different params*/)));
如何指定我不希望它在失败时重新启动?
最佳答案
我不是 Java 用户,但我在 Interface DeferredTask 中看到了这一点我认为您可以使用:
Normal return from this method is considered success and will not retry unless
DeferredTaskContext.markForRetry()
is called. Exceptions thrown from this method will indicate a failure and will be processed as a retry attempt unless DeferredTaskContext.setDoNotRetry(boolean) was set totrue
.
关于java - 如何使Java(AppEngine)中的延迟任务在失败时不重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46805776/