java - Guaranteeing that a task is added to push queue only once in GAE -
i want ensure task — task operates on single entity — gets added push queue at-most-once, till such time added task finished. should able add same task — same entity — again.
a simple example task updates entity a. want able to:
- add task x update entity a push queue.
- while task x in queue entity a, other attempts add task x entity should fail.
- once finished, should once again able add task x entity a.
the simple solution seems to use task name incorporates both name of task x , unique id of entity a.
however, think approach doesn't satisfy condition 3: task names "tombstoned" uncontrollable period & can't re-used till then.
from docs:
an advantage of assigning own task names named tasks de-duplicated, means can use task names guarantee* task added once. de-duplication continues 9 days after task completed or deleted.
does mean task names can't re-used 9 days?
indeed, task names can't re-used 9 days after no longer in queue. safety reason ensure traces of previous identically-named tasks flushed entire distributed infra.
you encode in task name current timestamp, rounded full second, limit actual write rate 1/s (which max average write rate same entity group anyways). if fail enqueue task (because in queue) try enqueue 1 next second (if don't have alternate way of triggering update task). encode timestamp towards end of task name, not beginning, avoid performance implications mentioned in same doc referenced.
Comments
Post a Comment