Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
    def test_unstick(self):
        # Simulate a broken batch job with a database footprint
        create_stuck_batch_job()
        self.assertTrue(BatchJob.get())
        self.assertTrue(Student.get_all_id_numbers())
        
        # Queue and fire the unstick task
        driver.queue_unstick()
        tasks = self.taskqueue_stub.get_filtered_tasks()
        self.assertEqual(len(tasks), 1)
        result = deferred.run(tasks[0].payload)

        # Ensure relevant DB tables have been cleared
        self.assertFalse(BatchJob.get())
        self.assertFalse(Student.get_all_id_numbers())
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
def create_stuck_batch_job():
    job = BatchJob.get_or_create()
    get_dummy_student().put()