diff --git a/docs/components/AssemblyLine/background_assembly.md b/docs/components/AssemblyLine/background_assembly.md new file mode 100644 index 000000000..b4a4ffd65 --- /dev/null +++ b/docs/components/AssemblyLine/background_assembly.md @@ -0,0 +1,169 @@ +--- +id: background_assembly +title: | + Assembling documents in the background +sidebar_label: | + Assembling documents in the background +slug: background_assembly +--- + +Assembly Line `3.2.0` and later introduce a background processing option to the [ALDocumentBundle](al_document.md) +class. + +Background processing: + +* Is safer when your user may generate large documents that take more than 60 seconds to assemble or convert to PDF +* Prevents frustrating 504 gateway timeout errors + +Negatives include: + +* Requires more care from the developer +* Usually prevents you from using an "edit" button on the final screen +* Means assembling documents will always take at least 10 seconds + +If your users currently have to wait a long time to get their finished documents, or if your users +ever see an error screen because the downloads took too long to make, you should use background processing. + +If you have only a few small documents and there is no user-provided content (like photos or +other uploaded exhibits), you should try without using background processing first. + +## Adding background processing to your interview + +Background processing is a built-in feature of the ALDocumentBundle class. Using it involves: + +1. Starting the built-in background assembly `task` in your interview order block +1. Setting conditions on when to display a waiting screen +1. Editing the download screen so it makes use of the background assembled documents + +In most cases, when you use background processing, you should also: + +1. Disable the preview screen +1. Show a review screen in-line before the download screen. + +### Editing your interview order block + +Find the line in your interview order block where you would like to start the background +assembly. In most cases, this should be just before the download screen. + +Add a line like this: + +```python + if not al_user_bundle.generate_downloads_with_docx_task.ready(): + al_download_waiting_screen +``` + +:::warning Make sure all required variables are defined + +Background assembly requires that all of the logic required to assemble your documents +was triggered **before** the background processing starts. You cannot have any +undefined variables that are needed for the document to generate. + +Note that if you use `skip undefined` this isn't usually a problem. +::: + +In some cases, you may want to start the background assembly earlier than just before the download screen. +For example, you may want to show the user instructions, or get information for a task +that will not change the documents, such as eFiling. + +### Editing the download screen + +On the download screen, edit the reference to `download_list_html()` to let it use +the background assembled documents. Using cached files is disabled by default. + +```yaml +--- +id: download +event: download_screen +question: | + Download the documents +subquestion: | + Your documents are ready for download. + + If you need to make any changes, click the "Undo" button and click the button to edit + the answer you want to change. + + ${ al_user_bundle.download_list_html(use_previously_cached_files=True, include_full_pdf=True) } +``` + +### And don't forget + +* Remove the preview screen. A waiting screen before the preview isn't a good user experience for most interviews. +* Add the review screen to your interview order block. The user will not be able to click the "edit answers" button + on the download screen. + +### Customizing the user experience + +#### What happens in the background task + +You may want to provide a non-default set of options to the file generation step. + +Override `al_user_bundle.generate_downloads_with_docx_task` or define a task with your +own name. The default contents of this task are: + +```yaml +--- +generic object: ALDocumentBundle +event: x.create_downloads_with_docx +code: | + download_response = x.get_cacheable_documents(key="final", pdf=True, docx=True, include_full_pdf=True) + background_response_action(x.attr_name('save_downloads'), download_response=download_response) +``` + +#### The waiting screen + +Override `al_download_waiting_screen`, or define a screen with your own name. The default contents +of this question block are: + +``` +--- +id: waiting screen +question: | + Please wait while we make your documents +subquestion: | + This can take a few minutes. +