Coverage for src / lexigram / contracts / tenancy / events.py: 0%
61 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-15 18:57 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-15 18:57 +0800
1"""Tenancy domain events."""
3from __future__ import annotations
5from dataclasses import dataclass
6from datetime import datetime
7from typing import Any
10@dataclass(frozen=True)
11class TenantProvisioned:
12 """Published when a new tenant is fully provisioned and active.
14 Attributes:
15 tenant_id: Unique identifier of the newly provisioned tenant.
16 slug: URL-safe slug for the tenant.
17 plan: Subscription plan assigned at creation (if any).
18 timestamp: UTC timestamp of the provisioning event.
19 """
21 tenant_id: str
22 slug: str
23 plan: str | None
24 timestamp: datetime
27@dataclass(frozen=True)
28class TenantActivated:
29 """Published when a previously inactive or suspended tenant is activated.
31 Attributes:
32 tenant_id: Unique identifier of the activated tenant.
33 timestamp: UTC timestamp of the activation event.
34 """
36 tenant_id: str
37 timestamp: datetime
40@dataclass(frozen=True)
41class TenantSuspended:
42 """Published when a tenant is suspended.
44 Attributes:
45 tenant_id: Unique identifier of the suspended tenant.
46 reason: Human-readable reason for the suspension (optional).
47 timestamp: UTC timestamp of the suspension event.
48 """
50 tenant_id: str
51 reason: str | None
52 timestamp: datetime
55@dataclass(frozen=True)
56class TenantDeactivated:
57 """Published when a tenant is deactivated.
59 Attributes:
60 tenant_id: Unique identifier of the deactivated tenant.
61 timestamp: UTC timestamp of the deactivation event.
62 """
64 tenant_id: str
65 timestamp: datetime
68@dataclass(frozen=True)
69class TenantConfigChanged:
70 """Published when a per-tenant configuration value is updated.
72 Attributes:
73 tenant_id: Unique identifier of the tenant whose config changed.
74 key: Configuration key that was modified.
75 old_value: The previous value (may be ``None`` if newly set).
76 new_value: The new value.
77 timestamp: UTC timestamp of the configuration change event.
78 """
80 tenant_id: str
81 key: str
82 old_value: Any
83 new_value: Any
84 timestamp: datetime
87@dataclass(frozen=True)
88class TenantTierMigrationStarted:
89 """Published when a tenant tier migration begins.
91 Attributes:
92 tenant_id: The tenant being migrated.
93 source_tier: The isolation tier being migrated from.
94 target_tier: The isolation tier being migrated to.
95 saga_id: The saga instance identifier for tracking.
96 timestamp: UTC timestamp of the event.
97 """
99 tenant_id: str
100 source_tier: str
101 target_tier: str
102 saga_id: str
103 timestamp: datetime
106@dataclass(frozen=True)
107class TenantTierMigrationSucceeded:
108 """Published when a tenant tier migration completes successfully.
110 Attributes:
111 tenant_id: The tenant that was migrated.
112 source_tier: The isolation tier migrated from.
113 target_tier: The isolation tier migrated to.
114 saga_id: The saga instance identifier for tracking.
115 duration_ms: Wall-clock duration of the migration in milliseconds.
116 timestamp: UTC timestamp of the event.
117 """
119 tenant_id: str
120 source_tier: str
121 target_tier: str
122 saga_id: str
123 duration_ms: int
124 timestamp: datetime
127@dataclass(frozen=True)
128class TenantTierMigrationFailed:
129 """Published when a tenant tier migration fails.
131 Attributes:
132 tenant_id: The tenant that failed migration.
133 source_tier: The isolation tier being migrated from.
134 target_tier: The isolation tier being migrated to.
135 saga_id: The saga instance identifier for tracking.
136 error: Human-readable description of the failure.
137 timestamp: UTC timestamp of the event.
138 """
140 tenant_id: str
141 source_tier: str
142 target_tier: str
143 saga_id: str
144 error: str
145 timestamp: datetime
148@dataclass(frozen=True)
149class TenantTierMigrationCheckpoint:
150 """Published when a saga stage checkpoint is reached during migration.
152 Attributes:
153 tenant_id: The tenant being migrated.
154 saga_id: The saga instance identifier.
155 stage: The stage name (e.g. ``"validate"``, ``"copy_data"``).
156 status: The stage status (e.g. ``"completed"``, ``"failed"``).
157 timestamp: UTC timestamp of the checkpoint.
158 """
160 tenant_id: str
161 saga_id: str
162 stage: str
163 status: str
164 timestamp: datetime
167__all__ = [
168 "TenantActivated",
169 "TenantConfigChanged",
170 "TenantDeactivated",
171 "TenantProvisioned",
172 "TenantSuspended",
173 "TenantTierMigrationCheckpoint",
174 "TenantTierMigrationFailed",
175 "TenantTierMigrationStarted",
176 "TenantTierMigrationSucceeded",
177]