Skip to content

Commit

Permalink
Stop caching failed PDF rendering logs; DMOJ#1119
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjaclasher authored and Xyene committed Oct 27, 2019
1 parent 26a9b48 commit 2da3164
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
6 changes: 2 additions & 4 deletions judge/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ def problem_update(sender, instance, **kwargs):
for lang, _ in settings.LANGUAGES])
cache.delete_many(['generated-meta-problem:%s:%d' % (lang, instance.id) for lang, _ in settings.LANGUAGES])

if hasattr(settings, 'DMOJ_PDF_PROBLEM_CACHE'):
for lang, _ in settings.LANGUAGES:
unlink_if_exists(get_pdf_path('%s.%s.pdf' % (instance.code, lang)))
unlink_if_exists(get_pdf_path('%s.%s.log' % (instance.code, lang)))
for lang, _ in settings.LANGUAGES:
unlink_if_exists(get_pdf_path('%s.%s.pdf' % (instance.code, lang)))


@receiver(post_save, sender=Profile)
Expand Down
7 changes: 0 additions & 7 deletions judge/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,8 @@ def get(self, request, *args, **kwargs):
except ProblemTranslation.DoesNotExist:
trans = None

error_cache = os.path.join(settings.DMOJ_PDF_PROBLEM_CACHE, '%s.%s.log' % (problem.code, language))
cache = os.path.join(settings.DMOJ_PDF_PROBLEM_CACHE, '%s.%s.pdf' % (problem.code, language))

if os.path.exists(error_cache):
with open(error_cache) as f:
return HttpResponse(f.read(), status=500, content_type='text/plain')

if not os.path.exists(cache):
self.logger.info('Rendering: %s.%s.pdf', problem.code, language)
with DefaultPdfMaker() as maker, translation.override(language):
Expand All @@ -268,8 +263,6 @@ def get(self, request, *args, **kwargs):
maker.load(file, os.path.join(settings.DMOJ_RESOURCES, file))
maker.make()
if not maker.success:
with open(error_cache, 'wb') as f:
f.write(maker.log)
self.logger.error('Failed to render PDF for %s', problem.code)
return HttpResponse(maker.log, status=500, content_type='text/plain')
shutil.move(maker.pdffile, cache)
Expand Down

0 comments on commit 2da3164

Please sign in to comment.