Reputation: 369
Upvotes: 9
Views: 4542
Reputation: 457
Using TaskQueue API
public class Enqueue extends HttpServlet {
private static final Logger log = Logger.getLogger(Enqueue.class.getName());
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String param1= request.getParameter("param1");
String param2= request.getParameter("param2");
String time = request.getParameter("time");
int timer = Integer.parseInt(time) * 1000;//sec to millisec
log.info("Executing in "+ timer+" seconds");
// Add the task to the default queue.
// Execute in 5 seconds
Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withUrl("/index1").param("param1", param1)
.param("param2", param2)
.countdownMillis(time));
response.sendRedirect("/");
}
}
Now define the job in Index1 class
public class Index1 extends HttpServlet {
private static final Logger log = Logger.getLogger(Index1.class.getName());
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String param1= req.getParameter("param1");
String param2= req.getParameter("param2");
log.info("Worker processing " + param1);
/*Define job to be executed*/
}
}
Upvotes: 0
Reputation: 4278
Per @Peter Recore's comment, the countdown
field in add()
is "Time in seconds into the future that this Task should execute. Defaults to zero."
Documentation: https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.taskqueue
Upvotes: 2
Reputation: 1034
In PHP
$task = new PushTask(
'/some/callback',
['param1' => $param1, 'param2' => $param2, 'param3' => $param3],
['name'=>'EmailTask', 'method'=>'POST', 'delay_seconds'=>30]
);
Or more simply (it is a POST by default)
$task = new PushTask(
'/some/callback',
['param1' => $param1, 'param2' => $param2, 'param3' => $param3],
['delay_seconds'=>30]
);
Upvotes: 2
Reputation: 3268
Google has updated this portion of their api (see here). You can now send in a 3rd parameter with PushTask containing the following options:
Upvotes: 1
Reputation: 101149
If you mean 'at least X minutes from now', yes - use the task queue API.
Upvotes: 4