PART 1: Created and implemented enums throughout the codebase to replace hardcoded status strings, improving type safety and reducing the risk of typos.

This commit is contained in:
Beverly Nguyen
2025-07-04 16:37:04 -07:00
parent db20c888f2
commit b73b4ac73e
12 changed files with 132 additions and 45 deletions

View File

@@ -4,21 +4,22 @@ from zoneinfo import ZoneInfo
from app.extensions import redis_client
from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
from app.utils.csv import get_user_preferred_timezone
from app.enums import JobStatus
class JobApiClient(NotifyAdminAPIClient):
JOB_STATUSES = {
"scheduled",
"pending",
"in progress",
"finished",
"cancelled",
"sending limits exceeded",
"ready to send",
"sent to dvla",
JobStatus.SCHEDULED.value,
JobStatus.PENDING.value,
JobStatus.IN_PROGRESS.value,
JobStatus.FINISHED.value,
JobStatus.CANCELLED.value,
JobStatus.SENDING_LIMITS_EXCEEDED.value,
JobStatus.READY_TO_SEND.value,
JobStatus.SENT_TO_DVLA.value,
}
SCHEDULED_JOB_STATUS = "scheduled"
CANCELLED_JOB_STATUS = "cancelled"
SCHEDULED_JOB_STATUS = JobStatus.SCHEDULED.value
CANCELLED_JOB_STATUS = JobStatus.CANCELLED.value
NON_CANCELLED_JOB_STATUSES = JOB_STATUSES - {CANCELLED_JOB_STATUS}
NON_SCHEDULED_JOB_STATUSES = JOB_STATUSES - {
SCHEDULED_JOB_STATUS,
@@ -57,7 +58,7 @@ class JobApiClient(NotifyAdminAPIClient):
job["original_file_name"],
)
for job in self.get_jobs(service_id, limit_days=0)["data"]
if job["job_status"] != "cancelled"
if job["job_status"] != JobStatus.CANCELLED.value
)
def get_page_of_jobs(self, service_id, *, page, statuses=None, limit_days=None):