Custom Stages¶
Create custom stages by subclassing Stage and registering with the registry.
Creating a Stage¶
from uptimer.stages.base import Stage, CheckResult, Status
from uptimer.stages.registry import register_stage
@register_stage
class MyStage(Stage):
"""My custom stage."""
name = "my-stage"
description = "My custom health check"
def check(self, url: str, verbose: bool = False) -> CheckResult:
"""Perform the check."""
# Your check logic here
return CheckResult(
status=Status.UP,
url=url,
message="OK",
elapsed_ms=100.0,
details={"custom": "data"},
)
Stage Base Class¶
Stage
¶
Bases: ABC
Base class for all stages.
Source code in src/uptimer/stages/base.py
Functions¶
check(url, verbose=False, context=None)
abstractmethod
¶
Perform the check and return result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to check |
required |
verbose
|
bool
|
Whether to include verbose output |
False
|
context
|
CheckContext | None
|
Optional context from previous stages |
None
|
Returns:
| Type | Description |
|---|---|
CheckResult
|
CheckResult with status, message, and details |
Source code in src/uptimer/stages/base.py
CheckResult¶
CheckResult
dataclass
¶
Status Enum¶
Status
¶
Registry Functions¶
register_stage¶
Register a stage class with the registry.
get_stage¶
Get a stage class by name.
from uptimer.stages.registry import get_stage
stage_class = get_stage("http")
stage = stage_class()
result = stage.check("https://example.com")
list_stages¶
List all registered stage names.