Skip to content

Commit 5ca8d9b

Browse files
committed
docs: Add supervisor docs page
1 parent 8fa392e commit 5ca8d9b

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Its purpose is to connect "smart home" devices via different communication proto
2121
variables_expressions
2222
datatypes
2323
timer
24+
supervisor
2425
web
2526
log
2627
interfaces

docs/interfaces_custom.rst

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ Interface Base and Helper Classes Reference
1313
.. autoclass:: AbstractInterface
1414
:members:
1515

16-
.. autoclass:: ServiceStatus
17-
18-
.. autoclass:: InterfaceStatus
19-
2016
.. autofunction:: interface_failure
2117

2218

docs/supervisor.rst

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
Start, Stop and Status Monitoring
3+
=================================
4+
5+
A typical SHC application consists of multiple parallel activities that need to be initialized and gracefully stopped at shutdown:
6+
Most *Interfaces* have an internal loop task for interacting with external systems and each of SHC's :ref:`timers <timer>` has an internal loop to wait for the next trigger time.
7+
In addition, “initializable” *Reading* objects, like SHC :ref:`variables` need to read their initial value during startup.
8+
9+
For this purpose, the :mod:`shc.supervisor` module implements functions for controlling startup and shutdown of SHC applications.
10+
11+
The main entry point of SHC applications, after all objects have been constructed and *connected*, should be the :func:`shc.supervisor.main` function, we already encountered in the examples.
12+
It performs the following startup procedure:
13+
14+
* Register a signal handler to initiate shutdown when receiving a SIGTERM (or similar)
15+
* Start all interface instances via their :meth:`start() <shc.supervisor.AbstractInterface.start>` coroutine and await their successful startup
16+
* Trigger initialization of variables via *read*
17+
* Start timers (incl. :class:`Once <shc.timer.Once>` triggers)
18+
19+
When a shutdown is initiated, all interfaces (and the SHC timers) are stopped by calling and awaiting their :meth:`stop() <shc.supervisor.AbstractInterface.stop>` coroutine.
20+
The SHC application only quits when all these coroutines have returned successfully.
21+
22+
When an interface fails starting up, it shall raise an exception from its :meth:`start() <shc.supervisor.AbstractInterface.start>` coroutine, which will interrupt the SHC startup process.
23+
24+
When an interface encounters a critical error during operation, after successful startup, it may call :func:`shc.supervisor.interface_failure` to initiate a shutdown.
25+
In this case, SHC will wait for the remaining interfaces to stop and exit with an non-zero exit code.
26+
27+
Some interfaces, especially client interfaces inheriting from :class:`shc.interfaces._helper.SupervisedClientInterface`, can be configured to automatically retry the external connection on errors, even if an an error is encountered during the initial startup.
28+
As the SHC application will continue to run in these cases, it's useful to monitor the status of individual interfaces.
29+
30+
31+
Monitoring of Interface Status
32+
------------------------------
33+
34+
For this purpose, most interfaces, implement a "monitoring connector" (also called "status connector").
35+
It is a *Readable* object of value type :class:`shc.supervisor.InterfaceStatus` that be retrieved via the :meth:`monitoring_connector <shc.supervisor.AbstractInterface.monitoring_connector>`.
36+
37+
If an interfaces does not provide monitoring capabilities, this method will raise a :class:`NotImplementedError`.
38+
39+
In many cases, the monitoring connector object is not only *Readable* but also *Subscribable*.
40+
This can be used to interactively react to interface status changes, e.g. set some variables to an emergency-fallback mode when the :class:`SHC client <shc.interfaces.shc_client.SHCWebClient>` connection to a primary SHC server is lost.
41+
42+
.. autoclass:: shc.supervisor.ServiceStatus
43+
44+
.. autonamedtuple:: shc.supervisor.InterfaceStatus
45+
46+
47+
Monitoring via HTTP
48+
^^^^^^^^^^^^^^^^^^^
49+
50+
TODO monitoring via HTTP using the WebServer
51+
52+
TODO :meth:`shc.web.interface.WebServer.configure_monitoring`
53+
54+
55+
56+
57+
Monitoring Helper classes
58+
^^^^^^^^^^^^^^^^^^^^^^^^^
59+
60+
TODO :class:`shc.interfaces.system_monitoring.EventLoopMonitor`
61+
62+

docs/web.rst

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ The constructor function must create at least two attributes on the constructed
392392
.. automethod:: page
393393
.. automethod:: add_menu_entry
394394
.. automethod:: api
395+
.. automethod:: configure_monitoring
395396
.. automethod:: serve_static_file
396397
.. automethod:: add_static_directory
397398

0 commit comments

Comments
 (0)