开发者

Can google.appengine.api.taskqueue payload argument be query result?

I'm trying to pass a query result to a taskqueue:

q = models.Spam.all()
results = q.fetch(10)
taskqueue.add(url='/_ah/queue/do-spams', payload=results)

This isn't working. I either have the argument structure wrong, or 开发者_如何学Cpayload cannot be result sets.


Instead of adding directly to a task queue I would use the deferred queue. Deferred Queues have similar functionality as task queues. One of the key features of deferred queues is that you can pass any type of data to one of your internal methods.

You specify the method you want to defer, the parameter values, and the deferred queue and appengine takes care of passing to data correctly.


From reading the documentation on taskqueue, I suspect that you need to pass a string, or at least a object, that has a string representation.

The payload data for this Task that will be delivered to the webhook as the HTTP request body. May be a string containing binary data.

http://code.google.com/appengine/docs/python/taskqueue/tasks.html#Task

Why isn't it working? Do you get an error? For a quick test you could try to pass it str(results). If it indeed does expect a string, you could try to serialize your results, e.g. JSON.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜