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

Rend publication_watchdog plus résistant aux exceptions #6264

Merged
Merged
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
47 changes: 27 additions & 20 deletions zds/tutorialv2/management/commands/publication_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,42 @@ 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(
"published_object", "published_object__content", "published_object__content__image"
).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:
Situphen marked this conversation as resolved.
Show resolved Hide resolved
# 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)