nexusLIMS.cli.process_records#

CLI command to process new NexusLIMS records.

This module provides a command-line interface for running the NexusLIMS record builder with file locking, timestamped logging, and email notifications. It replaces the functionality previously provided by process_new_records.sh.

Usage#

.. code-block:: bash

nexuslims build-records [OPTIONS]

Options#

.. code-block:: bash

-n, --dry-run   : Dry run mode (find files without building records)
-v, --verbose   : Increase verbosity (-v for INFO, -vv for DEBUG)
--from <date>   : Start date for filtering (ISO format). Defaults to 1 week ago.
                  Use "none" to disable lower bound.
--to <date>     : End date for filtering (ISO format). Omit to disable upper bound.
--version       : Show version and exit
--help          : Show help message and exit

Module Contents#

Functions#

setup_file_logging

Set up file logging with timestamped log file.

check_log_for_errors

Check log file for error patterns.

send_error_notification

Send error notification email.

main

Process new NexusLIMS records with logging and email notifications.

Data#

API#

nexusLIMS.cli.process_records.logger#

‘getLogger(…)’

nexusLIMS.cli.process_records.console#

‘Console(…)’

nexusLIMS.cli.process_records.ERROR_PATTERNS#
nexusLIMS.cli.process_records.EXCLUDE_PATTERNS#

[‘Temporary failure in name resolution’, ‘NoDataConsentError’, ‘NoMatchingReservationError’]

nexusLIMS.cli.process_records.setup_file_logging(dry_run: bool = False) tuple[Path, FileHandler][source]#

Set up file logging with timestamped log file.

Creates a log directory structure based on the current date and adds a FileHandler to the root logger. Log files are named with timestamps in the format YYYYMMDD-HHMM.log (or YYYYMMDD-HHMM_dryrun.log for dry runs).

Note: This function removes any existing FileHandlers from the root logger before adding the new handler to prevent handler accumulation across multiple invocations (important for testing scenarios where the same process runs multiple CLI commands).

Parameters:

dry_run (bool) – If True, append ‘_dryrun’ to the log filename

Returns:

A tuple containing:

  • Path to the created log file

  • The FileHandler instance that was added to the root logger

Return type:

tuple[Path, FileHandler]

Raises:

OSError – If log directory creation fails

nexusLIMS.cli.process_records.check_log_for_errors(log_path: Path) tuple[bool, list[str]][source]#

Check log file for error patterns.

Reads the log file and searches for error patterns (critical, error, fatal) while excluding known non-critical error patterns.

Parameters:

log_path (Path) – Path to the log file to check

Returns:

A tuple containing:

  • bool: True if errors were found, False otherwise

  • list[str]: List of error pattern names that were found

Return type:

tuple[bool, list[str]]

Raises:

FileNotFoundError – If the log file doesn’t exist

nexusLIMS.cli.process_records.send_error_notification(log_path: Path, found_patterns: list[str]) None[source]#

Send error notification email.

Sends an email notification with the log file contents when errors are detected. Email sending is skipped if email configuration is not available.

Parameters:
  • log_path (Path) – Path to the log file to include in the email

  • found_patterns (list[str]) – List of error pattern names that were found in the log

Returns:

This function doesn’t return anything. Errors are logged but not raised.

Return type:

None

Notes:

  • Email sending is gracefully skipped if configuration is missing

  • Any email sending errors are logged but don’t cause the function to fail

  • Uses SMTP with TLS encryption if configured

nexusLIMS.cli.process_records.main(*, dry_run: bool, verbose: int, from_arg: str | None, to_arg: str | None) None#

Process new NexusLIMS records with logging and email notifications.

This command runs the NexusLIMS record builder to process new experimental sessions and generate XML records. It provides file locking to prevent concurrent runs, timestamped logging, and email notifications on errors.

By default, only sessions from the last week are processed. Use –from=none to process all sessions, or specify custom date ranges with –from and –to.