views:

40

answers:

1

I want to guarantee that a task is not in a task queue more then once, so I generate a unique name based on it's payload. But, that task name is reserved for up to 7 days, which is not what I want; I only want it reserved for the duration the task is queued; it could be immediately re-queued.

Once a Task with name N is written, any subsequent attempts to insert a Task named N will fail. Eventually (at least seven days after the task successfully executes), the task will be deleted and the name N can be reused.

Is there a way to check if the named task is already in the queue then add it if it's not? Or a totally different approach?

A: 

You need to take a different approach - for example, including the time interval over which you want the name to be unique in the task name, or including a 'job number' that you increment for each new task.

Nick Johnson
Nick has an example of computing a task name which includes the time interval [here](http://blog.notdot.net/2010/05/App-Engine-Cookbook-On-demand-Cron-Jobs) (though in Python the concept will be straightforward to implement in Java as well).
David Underhill
I get the solution as it applies to my situation, but I don't see how using tasks for updates at periodic intervals is different from using a cron job.
antony.trupe
I'm jealous that in python you're allowed to use dashes in task names.
antony.trupe
@antony Because you get to schedule the jobs at runtime, rather than having to pre-specify it in a configuration file at design time. There's also no need to schedule jobs for intervals that you know will have no work that requires doing.
Nick Johnson
@Nick gotchu. you should include the link to the post in your answer. thanks again.
antony.trupe