我有一个小的应用程序,后面有一个appengine。
我想在我的数据库中合并重复项并在任务队列中进行复制:
class MergeDuplicatesHandler(write_page.Handler):
def get(self):
self.render("mergeduplicateshandler.html")
def post(self):
adminpassword = self.request.get("adminpassword")
if adminpassword == secret.ADMINPASSWORD:
# Add the task to the default queue.
taskqueue.add(url='/merge_duplicates', params={'adminpassword': adminpassword})
self.redirect('/')
else:
self.response.out.write("Wrong password")
class MergeDuplicates(write_page.Handler):
def post(self):
adminpassword = self.request.get("adminpassword")
if adminpassword == secret.ADMINPASSWORD:
person_service.merge_duplicates()
write_page.Handler
是一个webapp2处理程序
编辑:
这是我的merge_duplicates函数:
def merge_duplicates():
people = get_all()
peopletodelete = []
count = 0
for p1 in people:
deleted = False
if p1.cellphone != "" and p1.cellphone is not None:
for pdel in peopletodelete:
if(p1.key().id() == pdel.key().id()):
deleted = True
if not deleted:
p1people = get_people_by_cellphone(p1.cellphone)
if p1people:
for p2 in p1people:
if(p1.key().id() != p2.key().id()):
p1 = merge_person(p1,p2)
try:
insert_or_update_person(p1.firstname,
p1.secondfirstname,
p1.lastname,
p1.secondlastname,
p1.cellphone,
p1.shortcellphone,
p1.workphone,
p1.secondworkphone,
p1.homephone,
p1.email,
p1.homenumber,
p1.workernum,
p1.username,
p1.password)
peopletodelete.append(p2)
count = count + 1
# logging.info("Merge Dups Inserting: {0}".format(p1.firstname))
except UnicodeDecodeError:
logging.error("Problem with: {0} {1}".format(p1.firstname,p1.lastname))
else:
# logging.info("Merge Dups Deleting: {0}".format(p1.firstname))
p1.delete()
for pdel in peopletodelete:
pdel.delete()
return count
def merge_person(p1,p2):
p1.firstname = merge_person_parameter(p1.firstname,p1.last_modified,p2.firstname,p2.last_modified)
p1.secondfirstname = merge_person_parameter(p1.secondfirstname,p1.last_modified,p2.secondfirstname,p2.last_modified)
p1.lastname = merge_person_parameter(p1.lastname,p1.last_modified,p2.lastname,p2.last_modified)
p1.secondlastname = merge_person_parameter(p1.secondlastname,p1.last_modified,p2.secondlastname,p2.last_modified)
p1.cellphone = merge_person_parameter(p1.cellphone,p1.last_modified,p2.cellphone,p2.last_modified)
p1.shortcellphone = merge_person_parameter(p1.shortcellphone,p1.last_modified,p2.shortcellphone,p2.last_modified)
p1.workphone = merge_person_parameter(p1.workphone,p1.last_modified,p2.workphone,p2.last_modified)
p1.secondworkphone = merge_person_parameter(p1.secondworkphone,p1.last_modified,p2.secondworkphone,p2.last_modified)
p1.homephone = merge_person_parameter(p1.homephone,p1.last_modified,p2.homephone,p2.last_modified)
p1.email = merge_person_parameter(p1.email,p1.last_modified,p2.email,p2.last_modified)
p1.homenumber = merge_person_parameter(p1.homenumber,p1.last_modified,p2.homenumber,p2.last_modified)
p1.workernum = merge_person_parameter(p1.workernum,p1.last_modified,p2.workernum,p2.last_modified)
p1.username = merge_person_parameter(p1.username,p1.last_modified,p2.username,p2.last_modified)
p1.password = merge_person_parameter(p1.password,p1.last_modified,p2.password,p2.last_modified)
return p1
def merge_person_parameter(param1,modified1,param2,modified2) :
if not param1:
if param2:
param1 = param2
if param1:
if param2:
if modified1 < modified2:
param1 = param2
return param1
所有这些在localhost上的开发中都非常有效。我把它上传到appengine。它运行任务,我看它运行,绝对没有。 它只是需要很长时间或其他什么?
答案 0 :(得分:0)
您可以在流程中添加日志,并在开发者控制台中查看应用引擎日志。