Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow jobs to choose when to save log output #1082

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions server/autograder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion server/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions server/jobs/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/jobs/moss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down