Lightning.WorkOrders.ExportWorker (Lightning v2.19.0-pre)

View Source

This module handles the export of work orders for a given project. The export process is performed asynchronously using the Oban background job system.

## Responsibilities

  • Enqueueing Export Jobs: The enqueue_export/2 function creates and enqueues an Oban job for exporting work orders based on the given project and search parameters.
  • Processing Exports: The perform/1 function is the main entry point for executing the export job. It retrieves the project, processes work orders, and handles the export process.
  • Export Logic: The export lists the matching work order ids up front, then walks them a page at a time. Each page batch-loads its runs, steps, log lines and dataclips, writes the logs and dataclips asynchronously, and appends its slice of the export data. Nothing spans a transaction: the whole point of paging is that no database connection is held while files are being written.
  • Error Handling: The module includes comprehensive error handling and logging to ensure that issues during the export process are recorded and can be diagnosed.
  • Zip File Creation: After processing, the exported files are compressed into a zip file for easy download or further use.

## Usage

  • To enqueue an export job, call enqueue_export/2 with the project and search parameters.
  • The export process is triggered by Oban and runs in the history_exports queue, limited to a single attempt per job.

## Example

  # Enqueue an export job
  Lightning.WorkOrders.ExportWorker.enqueue_export(project, search_params)

  # The job will run in the background and log the status of the export process.

This module is designed to handle potentially large datasets efficiently by using streaming, async processing, and error recovery mechanisms.

Summary

Functions

enqueue_export(project, project_file, search_params)