From c6233c260273af32e77b82c06d9c623325ef91f9 Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Sun, 20 Mar 2022 21:39:46 +0100 Subject: [PATCH] =?UTF-8?q?Rend=20publication=5Fwatchdog=20plus=20r=C3=A9s?= =?UTF-8?q?istant=20aux=20exceptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/publication_watchdog.py | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/zds/tutorialv2/management/commands/publication_watchdog.py b/zds/tutorialv2/management/commands/publication_watchdog.py index b1a9d09cb9..8368d590b0 100644 --- a/zds/tutorialv2/management/commands/publication_watchdog.py +++ b/zds/tutorialv2/management/commands/publication_watchdog.py @@ -26,7 +26,10 @@ def handle(self, *args, **options): while requested_events.count() == 0: time.sleep(60) - self.run() + try: + self.run() + except: + logger.exception("Exception during one publication_watchdog run.") def run(self): requested_events = PublicationEvent.objects.select_related( @@ -34,27 +37,31 @@ def run(self): ).filter(state_of_processing="REQUESTED") for publication_event in requested_events.iterator(): - content = publication_event.published_object - extra_content_dir = content.get_extra_contents_directory() - building_extra_content_path = Path( - str(Path(extra_content_dir).parent) + "__building", "extra_contents", content.content_public_slug - ) - if not building_extra_content_path.exists(): - building_extra_content_path.mkdir(parents=True) - base_name = str(building_extra_content_path) - md_file_path = base_name + ".md" - - logger.info("Exporting « %s » as %s", content.title(), publication_event.format_requested) - publication_event.state_of_processing = "RUNNING" - publication_event.save() - - publicator = PublicatorRegistry.get(publication_event.format_requested) try: + content = publication_event.published_object + extra_content_dir = content.get_extra_contents_directory() + building_extra_content_path = Path( + str(Path(extra_content_dir).parent) + "__building", "extra_contents", content.content_public_slug + ) + if not building_extra_content_path.exists(): + building_extra_content_path.mkdir(parents=True) + base_name = str(building_extra_content_path) + md_file_path = base_name + ".md" + + logger.info("Exporting « %s » as %s", content.title(), publication_event.format_requested) + publication_event.state_of_processing = "RUNNING" + publication_event.save() + + publicator = PublicatorRegistry.get(publication_event.format_requested) publicator.publish(md_file_path, base_name) - except FailureDuringPublication: - logger.error("Failed to export « %s » as %s", content.title(), publication_event.format_requested) + except: + # Update and save the publication state before logging, in case + # content.title() would raise an exception (it already used to + # happen!). publication_event.state_of_processing = "FAILURE" + publication_event.save() + logger.exception("Failed to export « %s » as %s", content.title(), publication_event.format_requested) else: - logger.info("Succeed to export « %s » as %s", content.title(), publication_event.format_requested) publication_event.state_of_processing = "SUCCESS" - publication_event.save() + publication_event.save() + logger.info("Succeed to export « %s » as %s", content.title(), publication_event.format_requested)