您如何在GAE的任务引擎中为任务设置ETA? [英] How do you set an ETA for a task in GAE's task engine?

查看:57
本文介绍了您如何在GAE的任务引擎中为任务设置ETA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在未来一个小时内运行任务.这是我正在做的,似乎没有用.

I'm trying to run a task an hour in the future. Here's what I'm doing, doesn't seem to work.

import static com.google.appengine.api.taskqueue.TaskOptions.Builder.*;


Calendar cal = Calendar.getInstance(); 
cal.setTime(new Date()); 
cal.add(Calendar.HOUR, 1); 
cal.getTime(); 

Queue queue = QueueFactory.getDefaultQueue();
queue.add(withUrl("/task/doMyThing").param("userId", userId).header("X-AppEngine-TaskETA", cal.getTime().getTime()+""));

-编辑

好,然后再澄清一下:当某人点击我的服务时,我想在他们点击该服务后一个小时调用Java方法.我认为任务队列是在App Engine上执行此操作的最佳方法.我认为除非ETA通过,否则队列将不会执行该任务.如果我以错误的方式进行操作,并且有更好的方法可以完成此操作,请告诉我.

OK then a little more clarification: When someone hits my service I want to call a Java method exactly an hour after they hit the service. I assumed the task queue was the best way to do that on App Engine. I thought the queue would not execute that task unless the ETA had passed. If I'm approaching this the wrong way and there's a better way to accomplish it please let me know.

-再次编辑

感谢您的回答,根据记录,这就是我所做的:

Thanks for the answers, for the record here's what I did:

Queue queue = QueueFactory.getDefaultQueue();
queue.add(withUrl("/task/sendReminder").param("userId", userId).countdownMillis(120000));

推荐答案

我已经完成了您要尝试执行的操作,但是使用python.我认为您要设置的标头是appengine从队列启动任务时设置的标头,而不一定是您在创建任务时设置的标头.我认为您正在寻找

I've done what you're trying to do but in python. I think the header you're trying to set is one that appengine sets when it starts a task from the queue and not necessarily one that you set when you're creating the task. I think you're looking for countdownMillis with a value of 3600000.

这篇关于您如何在GAE的任务引擎中为任务设置ETA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆