You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/registration.md
+73-1Lines changed: 73 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,9 @@ The `.with_registration()` method accepts these parameters:
91
91
retry_delay=2.0, # Seconds between retries
92
92
fail_on_error=False, # Abort startup on failure
93
93
timeout=10.0, # HTTP request timeout
94
+
enable_keepalive=True, # Enable periodic ping to keep service alive
95
+
keepalive_interval=10.0, # Seconds between keepalive pings
96
+
auto_deregister=True, # Automatically deregister on shutdown
94
97
)
95
98
```
96
99
@@ -106,6 +109,9 @@ The `.with_registration()` method accepts these parameters:
106
109
-**retry_delay** (`float`): Delay in seconds between retry attempts. Default: 2.0.
107
110
-**fail_on_error** (`bool`): If True, raise exception and abort startup on registration failure. If False, log warning and continue. Default: False.
108
111
-**timeout** (`float`): HTTP request timeout in seconds. Default: 10.0.
112
+
-**enable_keepalive** (`bool`): Enable periodic pings to keep service registered. Default: True.
113
+
-**keepalive_interval** (`float`): Seconds between keepalive pings. Default: 10.0.
114
+
-**auto_deregister** (`bool`): Automatically deregister service on shutdown. Default: True.
109
115
110
116
---
111
117
@@ -120,7 +126,51 @@ The `.with_registration()` method accepts these parameters:
120
126
5.**Payload Creation**: Serializes ServiceInfo to JSON (supports custom subclasses)
121
127
6.**Registration Request**: Sends POST to orchestrator endpoint
122
128
7.**Retry on Failure**: Retries with delay if request fails
123
-
8.**Logging**: Logs all attempts and final outcome
129
+
8.**Keepalive Started**: If enabled, background task starts pinging orchestrator
130
+
9.**Service Runs**: Service handles requests while staying alive via pings
131
+
10.**Shutdown**: On graceful shutdown, stops keepalive and optionally deregisters
132
+
11.**Logging**: Logs all registration, ping, and deregistration events
133
+
134
+
### Keepalive and TTL
135
+
136
+
Services can be configured to send periodic "ping" requests to the orchestrator to indicate they're still alive. The orchestrator tracks a Time-To-Live (TTL) for each service and automatically removes services that haven't pinged within the TTL window.
137
+
138
+
**How it works:**
139
+
140
+
1.**Initial Registration**: Service registers and receives response with:
141
+
-`id`: Unique ULID identifier for this service
142
+
-`ttl_seconds`: How long until service expires (default: 30 seconds)
143
+
-`ping_url`: Endpoint to send keepalive pings (automatically provided by orchestrator)
144
+
145
+
2.**Keepalive Loop**: Background task automatically sends PUT requests to `ping_url` every N seconds:
146
+
- Default interval: 10 seconds (configurable via `keepalive_interval`)
147
+
- Each ping resets the service's expiration time
148
+
- Failures are logged but don't crash the service
149
+
150
+
3.**TTL Expiration**: Orchestrator runs cleanup every 5 seconds:
151
+
- Removes services that haven't pinged within TTL window
152
+
- Logs expired services for monitoring
153
+
154
+
4.**Graceful Shutdown**: On service shutdown:
155
+
- Keepalive task stops (no more pings)
156
+
- Service explicitly deregisters (if `auto_deregister=True`)
157
+
- Immediate removal from registry
158
+
159
+
**Configuration examples:**
160
+
161
+
```python
162
+
# Default: keepalive enabled, auto-deregister on shutdown
163
+
.with_registration()
164
+
165
+
# Disable keepalive (rely on manual health checks)
166
+
.with_registration(enable_keepalive=False)
167
+
168
+
# Custom keepalive interval (faster pings)
169
+
.with_registration(keepalive_interval=5.0)
170
+
171
+
# Don't deregister on shutdown (let TTL expire naturally)
172
+
.with_registration(auto_deregister=False)
173
+
```
124
174
125
175
### Registration Payload
126
176
@@ -154,6 +204,28 @@ For custom ServiceInfo subclasses:
154
204
}
155
205
```
156
206
207
+
### Registration Response
208
+
209
+
The orchestrator responds with registration details, including the ping endpoint:
-`id`: Unique ULID identifier assigned by orchestrator
224
+
-`ttl_seconds`: Time-to-live in seconds (service must ping within this window)
225
+
-`ping_url`: Endpoint for keepalive pings (automatically used by the service)
226
+
227
+
**Important**: The `ping_url` is provided by the orchestrator - services don't need to configure it. The service automatically uses this URL for keepalive pings when `enable_keepalive=True`.
0 commit comments