python - Getting task by name from taskqueue -
how can task name?
from google.appengine.api import taskqueue taskqueue.add(name='foobar', url='/some-handler', params={'foo': 'bar'} task_queue = taskqueue.queue('default') task_queue.delete_tasks_by_name('foobar') # work # looking method this: foobar_task = task_queue.get_task_by_name('foobar')
it should possible rest api (https://developers.google.com/appengine/docs/python/taskqueue/rest/tasks/get). prefer task_queue.get_task_by_name('foobar')
. ideas? did miss something?
there no guarantee task name exists - may have been executed. , if manage get
task, may executed while trying it. when try put back, have no idea if adding first time or second time.
because of uncertainty, can't see use case getting task name may useful.
edit:
you can give name task in order ensure particular task executes once. when add task name queue, app engine check if task such name exists. if does, subsequent attempt fail.
for example, can have many instances running, , each instance may need insert entity in datastore. first option check if entity exists in datastore. relatively slow operation, , time received response (entity not exist) , decide insert it, instance have inserted it. end 2 entities instead of one.
your second option use tasks. instead of inserting new entity directly datastore, instance creates task insert it, , gives task name. if instance tries add task same name, override existing task. result, guaranteed entity inserted once.
Comments
Post a Comment