# HG changeset patch # User Sverre Rabbelier # Date 1240152501 0 # Node ID c61f9dd5e325a582067ffe5ee5851a4dc910ed06 # Parent 0326d394dce55b452303c38b55535f8be7ec2421 Use status codes in job.py The previous behavior of being able go do 'if not handler.handle' is still valid as the status code for 'timed out' is 0. Patch by: Sverre Rabbelier diff -r 0326d394dce5 -r c61f9dd5e325 app/soc/cron/job.py --- a/app/soc/cron/job.py Sun Apr 19 14:45:22 2009 +0000 +++ b/app/soc/cron/job.py Sun Apr 19 14:48:21 2009 +0000 @@ -56,6 +56,12 @@ """Constructs a new Handler with all known jobs set. """ + self.OUT_OF_TIME = 0 + self.ALREADY_CLAIMED = 1 + self.SUCCESS = 2 + self.ABORTED = 3 + self.ERRORED = 4 + self.tasks = {} self.tasks['setupStudentProposalMailing'] = \ student_proposal_mailer.setupStudentProposalMailing @@ -153,12 +159,12 @@ if not job: # someone already claimed the job - return True + return self.ALREADY_CLAIMED if job.task_name not in self.tasks: logging.error("Unknown job %s" % job.task_name) db.run_in_transaction(self.abortJob, job_key) - return True + return self.ABORTED task = self.tasks[job.task_name] @@ -166,18 +172,18 @@ task(job) db.run_in_transaction(self.finishJob, job_key) - return True + return self.SUCCESS except DeadlineExceededError, exception: db.run_in_transaction(self.timeoutJob, job_key) - return False + return self.OUT_OF_TIME except FatalJobError, exception: logging.exception(exception) db.run_in_transaction(self.abortJob, job_key) - return True + return self.ABORTED except Exception, exception: logging.exception(exception) db.run_in_transaction(self.failJob, job_key) - return True + return self.ERRORED handler = Handler()