예제 #1
0
파일: main.py 프로젝트: henrique/DistEvo
 def put(self):
     logging.info('put all jobs received')
     
     if memcache.get(PutAllJobs._lockKey) is not None:
         logging.warn('jobs locked by another caller')
         self.error(204)
         return
     else:
         memcache.set(PutAllJobs._lockKey, True, 5) #5s
     
     data_string = self.request.body
     decoded = json.loads(data_string)
     logging.info(json.dumps(decoded, indent=2))
     
     if decoded.has_key('jobs'):
         jobs = decoded['jobs']
         logging.info('count jobs: ' + str(len(jobs)))
         
         data = Job.getAll()
         if data is not None:
             if data.count(1) > 0:
                 arch = Archive(key_name=str(data[0].iteration))
                 arch.jobs = Job.dump(data)
                 pop = Pop.all().get() #get current population to archive
                 if pop is not None:
                     arch.pop = pop.pop
                     arch.vals = pop.vals
                 arch.put()
         
         Job.putAll(jobs)
         memcache.delete(GetAllJobs.cachekey)
         memcache.delete(PutAllJobs._lockKey)
         
         email = self.request.get("email")
         if email:
             logging.info(email)
             from google.appengine.api import mail
             mail.send_mail(sender=email, to=email, subject="New iteration started", body=data_string)