Celery tasks

MEG Docs

(celery task)megdocs.tasks.parse_document_content(version_id: int)

Proxy that evaluates object once.

Proxy will evaluate the object each time, while the promise will only evaluate it once.

(celery task)megdocs.tasks.send_review_notifications()

Proxy that evaluates object once.

Proxy will evaluate the object each time, while the promise will only evaluate it once.

(celery task)megdocs.tasks.share_document(recipient_id: int, sharer_name: str, document_id: int, note: str = '') None

Emails a user to notify them that another user has shared a document with them.

Parameters:
  • recipient_id – The recipient auditor’s id.

  • sharer_name – Name of the user who shared the document.

  • document_id – The document’s id.

  • note – The note to be sent to the user

(celery task)megdocs.tasks.submit_draft_as_new_version(draft_id: int, auditor_id: int, version_data: dict, *, publish=False) int

Renders draft into a PDF file and submits a new version

Parameters:
  • draft_id – pk of the draft object

  • auditor_id – the id of the user who is creating the version

  • version_data – dict of any additional kwargs for the new Version

  • publish – whether to approve and publish the version automatically

Returns:

pk of the new version object

(celery task)megdocs.tasks.update_version_draft(version_id: int)

Updates version in review with the latest contents from draft:

  • pdf version

  • documents plaintext contents

This job runs if DRAFT_UPDATE_REVIEW is set

(celery task)megdocs.tasks.generate_pdf_preview(html: str) str

Generate a pdf document from given input HTML string. Uses html_to_pdf() to write preview to a temporary pdf file and returns its url (for example /media/CACHE/pdf_preview/0F0F0F0F0F0F0F.pdf). The preview file is deleted after time defined in PDF_PREVIEW_EXPIRY_MINS.

Uses file contents as the hash to determine filename, and if already exists, existing file is returned instead of rendering the pdf again.

Parameters:

html – The source HTML string

Returns:

the url to the generated PDF file

(celery task)megdocs.tasks.import_word_document_ckeditor(document_id: int, user_id: int) int

Imports document’s word version and creates or updates document’s draft with its contents. Creates draft object if one does not exist. If exists, overrides draft’s contents

The document’s current version must have a current version with “source” being a word docx file. The user must have access to the document

Parameters:
  • document_id – pk of the Document

  • user_id – pk of the User

Returns:

pk of the draft object

(celery task)megdocs.tasks.import_word_document_from_file_ckeditor(document_id: int, user_id: int, file_path: str) int

Parses The MS Word docx file and creates or updates Document’s draft with its contents. Creates draft object if one does not exist. If exists, overrides draft’s contents After successful import, the docx file is deleted.

Parameters:
  • document_id – pk of the Document

  • user_id – pk of the User - The user must have access to the document

  • file_path – absolute path to the Word DOCX file, must be in an accessible directory such as the /media/ folder

Returns:

pk of the draft object

(celery task)megdocs.tasks.create_user_notifications_documents_review(reviewer_id: int) None

Task to bulk create document review notifications for the versions reviewer Given the unique constraint on UserNotification, conflicts will be ignored in bulk create and duplicates will not be created

Param:

reviewer_id: the id of the documents versions reviewer that the notification will be created for

(celery task)megdocs.tasks.create_user_notifications_version_awaiting_publish(reviewer_id: int) None

Task to bulk create document publish notifications for the versions reviewer Given the unique constraint on UserNotification, conflicts will be ignored in bulk create and duplicates will not be created

Param:

reviewer_id: the id of the documents versions reviewer that the notification will be created for

(celery task)megdocs.tasks.create_user_notifications_version_publication_process(version_id: int) None

Task to bulk create document publication process notifications for those users in the version approval config’s current step that have not yet approved Given the unique constraint on UserNotification, conflicts will be ignored in bulk create and duplicates will not be created

Param:

version_id: the ids of the document version that will be queried to get the approval config and approvers

(celery task)megdocs.tasks.create_user_notifications_approval_config_publication_process(approval_config_id: int) None

Task to bulk create document publication process notifications for those users in the version approval config’s current step that have not yet approved Given the unique constraint on UserNotification, conflicts will be ignored in bulk create and duplicates will not be created

Param:

approval_config_id: the id of the approval config object by which the task was triggered

(celery task)megdocs.tasks.create_user_notifications_attestation_required(document_id: int) None

Create user notifications for documents that need to be attestation Queries the checkbox model associated with the document and annotates the auditor_ids on the model Loops through all relevant auditor ids for both teams and standalone auditors and creates a notification for each

Parameters:

document_id – The ID of the document that was recently updated with a new current version (published)

(celery task)megdocs.tasks.publish_document_version_from_schedule(version_id: int, auditor_id: int) None

Task to publish a document version checking if the auditor who invoked the task is indeed the reviewer

Parameters:
  • version_id – the id of the version to be published

  • auditor_id – the id of the auditor who triggered the task

(celery task)megdocs.tasks.delete_current_version_due_review_notifications(version_id: int)

Delete relevant notifcation when a version is marked as reviewed according to its interval

(celery task)megdocs.tasks.delete_relevant_version_notifications(version_id: int, current_step: int)

Update user notification by deleting the relevant notification based on the notification type

Parameters:
  • version_id – the version id for which the notification will be filtered by

  • current_step – the current step of the publication process

(celery task)megdocs.tasks.delete_previous_version_notifications(version_id: int) None

Task to cleanup any redundant notifications relevant to the version’s document Queries all previous versions of the document except the current version on publish and deletes stale notifications

Parameters:

version_id – The id of the version to exclude (document’s current version)

(celery task)megdocs.tasks.delete_existing_notification_approval_config(approval_config_id: int) None

Task to delete any redundant notifications relevant to the approval config’s documents

(celery task)megdocs.tasks.generate_llm_response_for_document_chat_message(auditor_id: int, ai_message_id: int, ai_chat_id: int, version_id: int) dict[str, bool]

Given an existing placeholder message and an AI chat, creates a LLM reply and updates the placeholder with the reply.

Steps:
  1. Feeds chat history to LLM and requests a new response

  2. If response contains a title adds the title to the chat.

  3. Updates placeholder-message content field object with LLM reply.

(celery task)megdocs.tasks.delete_attestation_required_notification(document_id: int, auditor_ids: list[int] | None = None) None

Delete attestation required notifications for specific auditors and document.

This task removes user notifications of type NOTIFICATION_TYPE_DOCUMENT_ATTESTATION_REQUIRED for the given auditors and document. It is typically called when: - A user completes an attestation (checks the checkbox) - A checkbox is deleted

Parameters:
  • document_id – The ID of the document for which to delete notifications

  • auditor_ids – List of auditor IDs whose notifications should be deleted

(celery task)megdocs.tasks.expire_checkbox_attestations(checkbox_id: int) None

Unpublish all DocumentCheckboxState records for a given checkbox when the review_interval has expired. This forces users to re-attest.

After expiring attestations, schedules the next expiration and reminder to maintain the review cycle.

Parameters:

checkbox_id – The ID of the DocumentCheckbox whose attestations should expire

(celery task)megdocs.tasks.send_attestation_reminder_emails(checkbox_id: int) None

Send reminder emails to users who have not yet attested to a document checkbox.

Parameters:

checkbox_id – The ID of the DocumentCheckbox to send reminders for

Files

(celery task)files.tasks.delete_media_file(path: str)

Deletes a file in the media folder. The task will fail if the file does not exist, of path leads outside the media folder. Use this task to lazily delete a file using celery or put it on a timer.

Parameters:

path – relative path to the preview file within media directory (for example CACHE/test.jpeg)

Raises:

FileNotFoundError – if the file does not exist