diff --git a/server/autograder.py b/server/autograder.py index 716f47e6c..160c2220a 100644 --- a/server/autograder.py +++ b/server/autograder.py @@ -178,6 +178,9 @@ def autograde_assignment(assignment_id): ] num_tasks = len(tasks) + if not num_tasks: + return "No submissions to grade" + def retry_task(task): if task.retries >= MAX_RETRIES: logger.error('Did not receive a score for backup {} after {} retries'.format( @@ -194,8 +197,10 @@ def retry_task(task): graded = len([task for task in tasks if task.status in (GradingStatus.DONE, GradingStatus.FAILED)]) - logger.info('Graded {:>4}/{} ({:>5.1f}%)'.format( - graded, num_tasks, 100 * graded / num_tasks)) + + logger.critical('Graded {:>4}/{} ({:>5.1f}%)'.format( + graded, num_tasks, 100 * graded / num_tasks)) + if graded == num_tasks: break diff --git a/server/jobs/__init__.py b/server/jobs/__init__.py index 31e79df00..5003a1276 100644 --- a/server/jobs/__init__.py +++ b/server/jobs/__init__.py @@ -22,7 +22,7 @@ def handle(self, record): self.counter += 1 super().handle(record) print(record.message) - if (self.counter % self.log_every) == 0: + if record.levelno >= logging.CRITICAL or not (self.counter % self.log_every): self.job.log = self.contents db.session.commit() diff --git a/server/jobs/example.py b/server/jobs/example.py index 2a6338635..fb75bb6a4 100644 --- a/server/jobs/example.py +++ b/server/jobs/example.py @@ -13,6 +13,8 @@ def test_job(duration=0, should_fail=False, make_file=False): logger = jobs.get_job_logger() logger.info('Starting...') + logger.critical('This job will sleep for {} seconds'.format(duration)) + time.sleep(duration) if should_fail: 1/0 diff --git a/server/jobs/moss.py b/server/jobs/moss.py index 38b4627e0..4043ea3da 100644 --- a/server/jobs/moss.py +++ b/server/jobs/moss.py @@ -44,7 +44,7 @@ def submit_to_moss(moss_id=None, file_regex=".*", assignment_id=None, language=N .order_by(Backup.created.desc()) .all()) - logger.info("Retreived {} final submissions".format(len(subm_keys))) + logger.info("Retrieved {} final submissions".format(len(subm_keys))) # TODO: Customize the location of the tmp writing (especially useful during dev) with tempfile.TemporaryDirectory() as tmp_dir: @@ -124,7 +124,7 @@ def submit_to_moss(moss_id=None, file_regex=".*", assignment_id=None, language=N .format(lang=language, templates=templates, folder=' '.join(all_student_files))) - logger.info("Running {}".format(command[:100] + ' ...')) + logger.critical("Running {}".format(command[:100] + ' ...')) try: process = subprocess.check_output(shlex.split(command), diff --git a/tests/test_job.py b/tests/test_job.py index 7c9649d91..e9228a8e2 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -44,7 +44,7 @@ def test_job(self): job = Job.query.get(job_id) self.assertEqual(job.status, 'finished') self.assertFalse(job.failed) - self.assertEqual(job.log, 'Starting...\nFinished!\n') + self.assertEqual(job.log, 'Starting...\nThis job will sleep for 0 seconds\nFinished!\n') def test_failing_job(self): job_id = self.start_test_job(should_fail=True)