📦 EqualifyEverything / equalify-reflow

📄 redis_schema.py · 98 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98"""Redis key patterns and schema utilities.

Provides consistent key naming functions for all Redis operations
across microservices. Ensures proper namespacing with eq-pdf prefix.
"""

from typing import Literal

# Redis key prefixes
REDIS_PREFIX = "eq-pdf"

# Queue type literals
QueueType = Literal["pii", "approval", "processing"]
TimeoutType = Literal["approval"]
MetricType = Literal["daily"]


def job_status_key(job_id: str) -> str:
    """Generate Redis key for job status hash.

    Args:
        job_id: UUID format job identifier

    Returns:
        Redis key string: eq-pdf:job:{job_id}

    Example:
        >>> job_status_key("550e8400-e29b-41d4-a716-446655440000")
        'eq-pdf:job:550e8400-e29b-41d4-a716-446655440000'
    """
    return f"{REDIS_PREFIX}:job:{job_id}"


def queue_key(queue_type: QueueType) -> str:
    """Generate Redis key for processing queue list.

    Args:
        queue_type: Type of queue (pii, approval, processing)

    Returns:
        Redis key string: eq-pdf:queue:{queue_type}

    Example:
        >>> queue_key("pii")
        'eq-pdf:queue:pii'
    """
    return f"{REDIS_PREFIX}:queue:{queue_type}"


def timeout_key(timeout_type: TimeoutType) -> str:
    """Generate Redis key for timeout sorted set.

    Args:
        timeout_type: Type of timeout tracking (approval)

    Returns:
        Redis key string: eq-pdf:timeouts:{timeout_type}

    Example:
        >>> timeout_key("approval")
        'eq-pdf:timeouts:approval'
    """
    return f"{REDIS_PREFIX}:timeouts:{timeout_type}"


def metrics_key(metric_type: MetricType) -> str:
    """Generate Redis key for metrics hash.

    Args:
        metric_type: Type of metrics (daily)

    Returns:
        Redis key string: eq-pdf:metrics:{metric_type}

    Example:
        >>> metrics_key("daily")
        'eq-pdf:metrics:daily'
    """
    return f"{REDIS_PREFIX}:metrics:{metric_type}"


# Constant queue keys for direct import
PII_QUEUE = queue_key("pii")
APPROVAL_QUEUE = queue_key("approval")
PROCESSING_QUEUE = queue_key("processing")

# Constant timeout keys
APPROVAL_TIMEOUTS = timeout_key("approval")

# Constant metric keys
DAILY_METRICS = metrics_key("daily")

# Job status key prefix for pattern matching
JOB_STATUS_PREFIX = f"{REDIS_PREFIX}:job:"

# Secondary index: sorted set of job keys ordered by last-updated timestamp
JOBS_BY_UPDATED = f"{REDIS_PREFIX}:jobs-by-updated"