def get(self): batchid = self.request.get('batchid') batch = db.get(batchid) uobjects = [] for user in batch.users: if User.all().filter("nickname=", user).count() > 0: continue #TODO query FF for the users prescriptions n = random.randint(1,10) friends = [ ("user%02d" % (random.randint(0,19))) for i in range(n)] u = User( nickname = user, friends = friends) uobjects += [ u ] db.put(uobjects) batch.done = True key = db.Key( str(batch.parent_key() )) batch.delete() #nbatches = Batch.all().ancestor( key ).filter("done=", True).count() nbatches = Batch.all(keys_only=True) nbatches = nbatches.ancestor( key ) nbatches = nbatches.count() logging.info("nbatches=%d" % nbatches) if nbatches == 0: job = db.get( key ) job.done = True job.put() t = Task(method="GET", url="/tasks/FinishJob?jobid=%s" % job.key()) t.add()