app/soc/cron/job.py
changeset 2229 b36ecf371aef
parent 2224 fc719e902a70
child 2243 c61f9dd5e325
equal deleted inserted replaced
2228:d58dd8963332 2229:b36ecf371aef
    86 
    86 
    87     job.status = 'waiting'
    87     job.status = 'waiting'
    88 
    88 
    89     return job.put()
    89     return job.put()
    90 
    90 
       
    91   def timeoutJob(self, job_key):
       
    92     """A transaction to tiemout a job.
       
    93     """
       
    94 
       
    95     job = Job.get_by_id(job_key)
       
    96 
       
    97     job.timeouts += 1
       
    98 
       
    99     if job.timeouts > 50:
       
   100       job.status = 'aborted'
       
   101     else:
       
   102       job.status = 'waiting'
       
   103 
       
   104     job_id = job.key().id()
       
   105     logging.debug("job %d now timeout %d time(s)" % (job_id, job.timeouts))
       
   106 
       
   107     return job.put()
       
   108 
    91   def failJob(self, job_key):
   109   def failJob(self, job_key):
    92     """A transaction to fail a job.
   110     """A transaction to fail a job.
    93     """
   111     """
    94 
   112 
    95     job = Job.get_by_id(job_key)
   113     job = Job.get_by_id(job_key)
   148       task(job)
   166       task(job)
   149 
   167 
   150       db.run_in_transaction(self.finishJob, job_key)
   168       db.run_in_transaction(self.finishJob, job_key)
   151       return True
   169       return True
   152     except DeadlineExceededError, exception:
   170     except DeadlineExceededError, exception:
   153       db.run_in_transaction(self.freeJob, job_key)
   171       db.run_in_transaction(self.timeoutJob, job_key)
   154       return False
   172       return False
   155     except FatalJobError, exception:
   173     except FatalJobError, exception:
   156       logging.exception(exception)
   174       logging.exception(exception)
   157       db.run_in_transaction(self.abortJob, job_key)
   175       db.run_in_transaction(self.abortJob, job_key)
   158       return True
   176       return True