Created
March 12, 2010 17:24
-
-
Save winhamwr/330547 to your computer and use it in GitHub Desktop.
celery task using wait()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_document_pdf(document, realtime=False, timeout=None, watermark=True): | |
""" | |
Builds and caches a PDF copy of this document. | |
If ``realtime`` is True, returns the URL to the PDF. Otherwise, the PDF is | |
generated as asynchronously in the background. | |
""" | |
if not timeout: | |
timeout = print_settings.PRINTING_TIMEOUT | |
pdf_generator = DocumentPdfGenerator() | |
if realtime: | |
result = pdf_generator.delay(document, watermark=watermark) | |
try: | |
result.wait(timeout) | |
if not result.successful(): | |
raise ValueError(result.result) | |
return result.result | |
except TimeoutError: | |
return reverse('printing_wait', kwargs={'task_id': result.task_id}) | |
else: | |
return pdf_generator.delay(document, watermark=watermark) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment