Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /terrene-foundation_kailash-py /packages /kailash-nexus /src /nexus /background.py
| # Copyright 2026 Terrene Foundation | |
| # SPDX-License-Identifier: Apache-2.0 | |
| from __future__ import annotations | |
| import logging | |
| from abc import ABC, abstractmethod | |
| logger = logging.getLogger(__name__) | |
| __all__ = ["BackgroundService"] | |
| class BackgroundService(ABC): | |
| """Abstract base class for Nexus background services. | |
| Background services are non-transport lifecycle components that run | |
| alongside the Nexus platform. Unlike transports (which handle network | |
| protocols), background services handle internal tasks: scheduled jobs, | |
| event-driven handlers, webhook delivery, etc. | |
| Lifecycle contract: | |
| 1. Service is instantiated and configured | |
| 2. Service is registered with Nexus via app.add_background_service() | |
| 3. Nexus.start() calls service.start() for all registered services | |
| 4. Service runs until Nexus.stop() calls service.stop() | |
| 5. is_healthy() is polled during health checks | |
| Concrete implementations: | |
| - SchedulerBackgroundService (TSG-222): runs @app.scheduled() handlers | |
| - WebhookDeliveryService (TSG-226): delivers outbound webhooks | |
| - BackgroundTaskManager (TSG-227): manages one-shot async tasks | |
| """ | |
| def name(self) -> str: | |
| """Unique name for this background service.""" | |
| ... | |
| async def start(self) -> None: | |
| """Start the background service. | |
| Called by Nexus.start() after the event loop is running. | |
| Must be idempotent (safe to call multiple times). | |
| """ | |
| ... | |
| async def stop(self) -> None: | |
| """Stop the background service gracefully. | |
| Called by Nexus.stop() during shutdown. Must complete within | |
| a reasonable timeout (default 30s). Must be idempotent. | |
| """ | |
| ... | |
| def is_healthy(self) -> bool: | |
| """Return True if the service is functioning correctly. | |
| Called during health checks. Should be fast (no I/O). | |
| """ | |
| ... | |
Xet Storage Details
- Size:
- 2.05 kB
- Xet hash:
- 643cd336239b8831e6a080406418106b2a602b40cb9a00e4a00c2b2674c251e6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.