0

I never used task queue before. I'm having a problem trying to get a report of all of my contacts from the datastore.

The code is:

allContactos=db.GqlQuery("select * from contactsDB").run(batch_size=1000)
for contactN in allContactos:
    ... (here I put all the fields in csv format)

The problem is that I'm getting a "500 Server Error" because of the massive quantity of contacts.

My question is, is it a good aproach to try to solve this with task queue? can you give me some tip to segregate that query in many tasks?

Regards!

lscena
  • 379
  • 2
  • 13

1 Answers1

0

You don't need to split your query in many tasks. You can start one task. If this task takes more than 10 minutes, you will have to use a backend to run this task.

You will to either email the file to a user when a task is finished, or create a link in your app/website to download this file when it's ready.

Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Thanks for your answer. How do I know when the task is finished? and how can I create a link to obtain the result of the task? – lscena Mar 10 '14 at 18:07
  • Note that if it takes over 10min you dont necessarily need a backend. Assuming a huge list you could query with pagination (page tokens) and have one task queue after the other, each does one page. But the output would have to be something like a drive text file and you keep appending to it. – Zig Mandel Mar 10 '14 at 18:19
  • Task chaining: http://blog.notdot.net/2010/03/Task-Queue-task-chaining-done-right – voscausa Mar 10 '14 at 18:47
  • Your task finishes when the last line of code in it is executed. You can send yourself (or a user) an email when the task finishes writing a file, for example. As for the link, your app can periodically query the server to see if the file is available. When it finds a file, it can display a link to retrieve it. – Andrei Volgin Mar 10 '14 at 21:43