1

Before adding a task to the pull queue, I have to confirm whether same task exists already within queue, if exists should skip task adding to queue. Adding task with name doesn't work for me as it doesn't expire until seven days from the queue even deleted.

We can list tasks using REST API. In the same way, can we get the list of tasks within GAE module or is there any other way to find whether task exists in the queue within Google App Engine module?

Thanks

Naresh M
  • 113
  • 11
  • I don't fully understand (you didn't explain it) your reasons for not being able to just use names and the REST API...? – Nick Sep 25 '15 at 19:43
  • Hi Nick, as per my requirement, same kind of tasks like notifications appears for a period (e.g., 5 min). So to avoid duplicate notifications, need to send First come First Serve manner for that duration (i.e., within that 5 min). So unique tasks need to run within that duration. – Naresh M Sep 29 '15 at 09:33
  • Can you explain in more details what you mean by `"Adding task with name doesn't work for me as it doesn't expire until seven days from the queue even deleted"`? – Nick Sep 29 '15 at 16:18
  • Also, what do you mean by `"can we get the list of tasks within GAE module or is there any other way to find whether task exists in the queue within Google App Engine module?"`? – Nick Sep 29 '15 at 16:19

1 Answers1

3

If task names does not work with logic of your app you can create a corresponding db entity (empty, just a key) that would serve as a flag that the tasks is in the queue. You should put it to db in transaction with a task and delete when task completed.

It would cost you 1 read & 4 write (2 for insert & 2 for delete) operations per each task - nothing comes free.

As alternative you can consider to have some counter in your business entity that would be a part of task name.

Let's say you have entity User and a property TaskCounter.

Then you would add task as:

tasks.add(taskName="TASKNAME" + str(user.id) + str(user.TaskCounter)) - that would insure you can have just 1 active task per entity. Of course you would need to update the property when the task finishes. If you update the entity in the task anyway it costs you almost nothing.

Alexander Trakhimenok
  • 6,019
  • 2
  • 27
  • 52
  • Thanks Alexander for your answer. I thought of using Memcache instead of db before, as it contains expire time for an entity too. – Naresh M Sep 29 '15 at 09:33
  • Memcache can work but is not guaranteed to keep value. So it's not guaranteed you would not insert a task multiple times. It should work most of the time but you should make your task to be independent (be able to run multiple times with the same arguments without breaking business logic). If the my answer satisfying you can mark it as accepted. – Alexander Trakhimenok Sep 29 '15 at 12:50