-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.py
More file actions
72 lines (55 loc) · 2.16 KB
/
node.py
File metadata and controls
72 lines (55 loc) · 2.16 KB
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
"""Launch a distributed sensor-hub node process.
Responsibilities:
- Initialize bootstrap logging and process-wide exception hooks.
- Load environment-backed node configuration and logging settings.
- Construct the runtime application that owns networking, membership,
sensor ingestion, LWW state replication, gossip-driven peer discovery,
and the monitoring API.
- Transfer control to the long-running node lifecycle until shutdown.
"""
import logging
from runtime.application import NodeApplication
from runtime.bootstrap import (
clear_log_file_if_requested,
install_global_exception_hooks,
setup_bootstrap_logging,
)
from utils.config import load_config
from utils.logging import get_logger, setup_logging
def main() -> None:
"""Start the node runtime from process bootstrap through steady state.
This function prepares logging, validates configuration, and starts the
application container that brings up the TCP protocol stack, membership
bootstrap, sensor event processing, and replicated state dissemination. Once
started, the node participates in best-effort gossip-style peer discovery and
last-writer-wins state convergence through the subsystems owned by
``NodeApplication``.
Returns:
None: This function blocks in the application main loop until the process
shuts down.
Raises:
Exception: Propagates configuration, logging, or runtime startup failures
after recording them through bootstrap or node logging.
"""
setup_bootstrap_logging()
install_global_exception_hooks()
bootstrap_log = logging.getLogger("bootstrap")
bootstrap_log.info("Node process starting")
try:
config = load_config()
except Exception:
bootstrap_log.critical("Failed to load configuration", exc_info=True)
raise
clear_log_file_if_requested(config.log_file, config.should_clear_log())
try:
setup_logging(config.node_id, config.log_level, config.log_file)
except Exception:
bootstrap_log.critical("Failed to setup logging", exc_info=True)
raise
log = get_logger(__name__, config.node_id)
log.info("Full logging initialized")
app = NodeApplication(config=config, log=log)
app.start()
app.run_forever()
if __name__ == "__main__":
main()