Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
celery task using wait()
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)
if not result.successful():
raise ValueError(result.result)
return result.result
except TimeoutError:
return reverse('printing_wait', kwargs={'task_id': result.task_id})
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