I created a task that handles batch delete for my application. The
purpose of the task is to delete records recursively. Once all records
are deleted, a new process must be started.

I tried to implement this through the code posted below. I really why
this is not working as expected, but for some reason, I end up having
many tasks running concurrently. Is this the expected behavior of the
TaskQueue?


Here's the actual code :

def post(self):
        task_unique_name = self.request.headers['X-AppEngine-TaskName']
        #Checks if task has been executed already
        if task.ExecutedTask.all().filter('task_name=',
task_unique_name).count():
                return;

        campaign_id = db.Key(self.request.POST['campaign_id'])

        def delete_transcation(camp):
                query = db.Query(Recipient,
keys_only=True).ancestor(campaign_id).filter('campaign', camp)
                results = query.fetch(app_model.DATASTORE_PUT_LIMIT)
                #If results are found, delete them and start a new delete task
                if results:
                        db.delete(results)
                        t = taskqueue.Task(url='/tasks/delete_recipients',
params=self.request.POST)
                        t.add(queue_name='recipients-import')

                #No results found to delete, start import if appropriate.
                elif self.request.POST.get('new_import', False)
                        
campaign.Campaign.get_cache(campaign_id).spawn_import_tasks()

                return True

        def mark_task_as_done():
                save_task = task.ExecutedTask(task_name=task_unique_name)
                save_task.put()

        if(db.run_in_transaction(delete_transcation, campaign_id)):
                db.run_in_transaction(mark_task_as_done)

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to