Working with Transfer Statuses

Our application uses a centralized TransferStatus enum to manage the status of various transfer operations, including LongTermArchiveTransfer transfers. This enum is configured using Dynaconf settings and provides a consistent interface for working with transfer statuses across the application.

Configuration

Transfer status values are defined in the Dynaconf settings file (settings.toml):

[default.status]
PENDING = "pending"
RUNNING = "running"
COMPLETED = "completed"
FAILED = "failed"

These values can be easily modified in the settings file without requiring changes to the core application code.

Usage

The TransferStatus enum is defined as follows:

from enum import Enum
from dynaconf import settings

class TransferStatus(Enum):
    PENDING = settings.transfer.status.PENDING
    RUNNING = settings.transfer.status.RUNNING
    COMPLETED = settings.transfer.status.COMPLETED
    FAILED = settings.transfer.status.FAILED

To use the TransferStatus enum in your code:

  1. Importing the enum:

    from ccat_ops_db.models import TransferStatus
    
  2. Setting a transfer status:

    transfer.status = TransferStatus.RUNNING
    
  3. Checking a transfer status:

    if transfer.status == TransferStatus.COMPLETED:
        print("Transfer completed successfully")
    
  4. Using the status in database queries:

    completed_transfers = session.query(LongTermArchiveTransfer).filter(
        LongTermArchiveTransfer.status == TransferStatus.COMPLETED
    ).all()
    

Benefits

Using the TransferStatus enum provides several advantages:

  1. Type safety: Prevents typos and ensures only valid status values are used.

  2. Centralized configuration: Status values can be easily modified in the Dynaconf settings.

  3. Consistency: Ensures consistent status naming across different parts of the application.

  4. Readability: Makes the code more self-documenting and easier to understand.

Remember to import and use TransferStatus instead of hardcoding status strings in your application code. This approach will make your code more maintainable and less prone to errors related to status management.