def __unstick(): """ DO NOT call this method directly, use queue_unstick() instead. """ logging.info("Clearing stuck batch job") logging.info("Wiping temporary records from student table") Student.delete_all() logging.info("Deleting batch job entity") BatchJob.get_or_create().key.delete() logging.info("Batch job cleared")
def __do_run(): """ Resume a suspended batch job if it exists, or create a new one if not. """ logging.info("Loading batch job") job = BatchJob.get_or_create() config = DeploymentConfig.get_instance() if not job.student_data_loaded: logging.info("Loading students to DB") load_students_to_db(config) job.student_data_loaded = True job.put() # The report generation step might take awhile for large data sets, # requeue here just in case to reset the task queue timer. # (Because of the sorting, it has to be completed atomically) queue() return if not job.reports_complete: logging.info("Generating reports") print_reports(config) job.reports_complete = True job.put() logging.info("Cleaning up temporary records") Student.delete_all() logging.info("Anonymizer run complete, terminating batch job") job.key.delete()
def test_job_put(self): # Ensure empty starting DB result = BatchJob().query().fetch(limit=None) self.assertFalse(result) # Ensure job was created job1 = BatchJob.get_or_create() result = BatchJob().query().fetch(limit=None) self.assertTrue(result) self.assertEqual(1, len(result)) # Ensure an existing job won't be recreated job2 = BatchJob.get_or_create() result = BatchJob().query().fetch(limit=None) self.assertTrue(result) self.assertEqual(1, len(result)) self.assertEqual(job1.key, job2.key)
def create_stuck_batch_job(): job = BatchJob.get_or_create() get_dummy_student().put()