PermanentTaskFailure: 'module'对象没有'Migrate'属性
我在谷歌的App Engine上使用Nick Johnson的批量更新库(http://blog.notdot.net/2010/03/Announcing-a-robust-datastore-bulk-update-utility-for-App-Engine)。这个库在其他任务上运行得很好,但在以下代码中:
from google.appengine.ext import db
from myapp.main.models import Story, Comment
import bulkupdate
class Migrate(bulkupdate.BulkUpdater):
DELETE_COMPLETED_JOBS_DELAY = 0
DELETE_FAILED_JOBS = False
PUT_BATCH_SIZE = 1
DELETE_BATCH_SIZE = 1
MAX_EXECUTION_TIME = 10
def get_query(self):
return Story.all().filter("hidden", False).filter("visible", True)
def handle_entity(self, entity):
comments = entity.comment_set
for comment in comments:
s = Story()
s.parent_story = comment.story
s.user = comment.user
s.text = comment.text
s.submitted = comment.submitted
self.put(s)
job = Migrate()
job.start()
我在日志中看到以下错误:
Permanent failure attempting to execute task
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/deferred/deferred.py", line 258, in post
run(self.request.body)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/deferred/deferred.py", line 122, in run
raise PermanentTaskFailure(e)
PermanentTaskFailure: 'module' object has no attribute 'Migrate'
这让我觉得很奇怪。很明显,这个类就在任务的上面,它们在同一个文件里,而且任务的start方法也被调用了。为什么它看不到我的Migrate类呢?
补充:我在代码的新版本中添加了这个更新任务,而这个版本不是默认的。我用正确的URL(http://version.myapp.appspot.com/migrate)来调用这个任务。难道这和它不是App Engine提供的“默认”版本有关吗?
1 个回答
7
看起来你定义的'Migrate'类是在处理脚本里(比如说,就是那个直接由app.yaml调用的脚本)。使用deferred的一个限制是,你不能用它来调用在处理模块里定义的函数。
顺便提一下,我的批量更新库已经不再推荐使用了,建议你使用App Engine的mapreduce支持;你可能应该用那个。