charliesneath
charliesneath

Reputation: 2039

Schedule a GET request with GAE

I've been researching ways to schedule a GET request with a GAE application. Specifically, I want my application to respond 1 hour after it's been requested by fetching a different URL that points to another app's API.

Are Deferred Tasks the way to handle this?

I also found that Tasks have an "eta" argument that specifies earliest time of execution. Could this be preferred over "_countdown"?

Or investigate Cron jobs? These GET requests won't be happening regularly, so I don't know if Cron jobs are appropriate.

Thanks! Please help me clarify if necessary.

Upvotes: 1

Views: 113

Answers (2)

Tim Hoffman
Tim Hoffman

Reputation: 12986

As long as you don't want to the second accuracy (say minute accuracy). I would add the request to the datastore implementing a queue of requests. Then have a cron job run every minute looking for requests scheduled for that time period. Then I would submit a task to perform the requests. Name the task so you are unlikely to have the same task re-submitted. The task can retry a couple of times (if it errors) then you can mark the request as completed in your queue.

This way you can handle any number of scheduled requests. You don't end up with thousands of tasks. You can know if requests will run, when they run etc...

Upvotes: -1

Lipis
Lipis

Reputation: 21835

Yes that's a good way to do it, all you have to do is to set the _countdown in your deferred call, which is how many seconds you want to wait until this task will be executed.

Example as from the docs:

deferred.defer(do_something_expensive, _countdown=3600, _queue="myqueue")

Or you can simply use the Task API where you can set all the different parameters on when and how exactly you want this task to be executed. Whatever suits you best you can use either eta or countdown, from GAE perspective it is exactly the same.

Upvotes: 2

Related Questions