Skip to content

Commit 8e0f2d7

Browse files
committed
Fix doc generation, introduce basic README.
Signed-off-by: George Melikov <[email protected]>
1 parent 77e4620 commit 8e0f2d7

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed

README.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,96 @@
1-
## Loopster
2-
Сервисная библиотека, которая обеспечивает выполнение сервисных процессов, следит за их зависаниями и при необходимости осуществляет перезапуск.
1+
# Loopster
2+
3+
Loopster is a service library that provides mechanisms for executing and managing services, including monitoring their status and automatically restarting them when necessary.
4+
5+
## Installation
6+
7+
To install Loopster, you can use pip:
8+
9+
```
10+
pip install loopster
11+
```
12+
13+
## Usage
14+
15+
### Basic Service Example
16+
17+
Here's an example of how to create and run a basic service using Loopster:
18+
19+
```python
20+
from loopster.hubs import base
21+
from loopster.hubs.controllers import panic
22+
from loopster.hubs.drivers import process
23+
from loopster.services import softirq
24+
25+
class BasicService(softirq.SoftIrqService):
26+
def _step(self):
27+
print("Hello, world!")
28+
29+
driver = process.ProcessDriver()
30+
controller = panic.PanicController()
31+
hub = base.BaseHub(driver=driver, controller=controller)
32+
33+
hub.add_service(svc_class=BasicService, svc_kwargs={})
34+
hub.serve()
35+
```
36+
37+
### Nested Service Example with MySQLWrapper
38+
39+
Here's an example of how to use a nested service with the `mysqlwrapper` module:
40+
41+
```python
42+
from restalchemy.storage.sql import engines
43+
from rooster.hubs.controllers import force_state
44+
from loopster.hubs.drivers import process
45+
from loopster.services import mysql
46+
from loopster.services import softirq
47+
48+
class BasicService(softirq.SoftIrqService):
49+
def _step(self):
50+
print("Hello, world!")
51+
52+
hub = process.ProcessHub(
53+
controller=force_state.AlwaysForceTargetStateController())
54+
55+
hub.add_service(
56+
svc_class=mysql.MySQLStorageWrapper,
57+
svc_kwargs=dict(
58+
nested_class=BasicService,
59+
nested_kwargs=dict(
60+
step_period=STEP_PERIOD,
61+
),
62+
mysql_connection_url=engines.DBConnectionUrl(CONNECTION_URL)
63+
)
64+
)
65+
```
66+
67+
## Public Interface
68+
69+
### Services
70+
71+
Loopster provides several built-in services, including:
72+
73+
- `SoftIrqService`: A service with a watchdog that runs in an infinite loop.
74+
- `BjoernService`: A special server for Bjoern, which implements multiprocessing by itself.
75+
76+
### Hubs
77+
The `ProcessHub` class is used to manage multiple services using one strategy provided by the driver. It inherits from `SoftIrqService`, so it's a service too!
78+
79+
Hub provides a simple way to start and stop multiple services at once, as well as monitor their status.
80+
81+
#### Features
82+
83+
- **Signal Handling**: The `ProcessHub` can handle signals such as SIGHUP and SIGUSR1, allowing for graceful shutdowns and other terminal actions.
84+
- **Multiprocessing Support**: By using the `multiprocessing` module, `ProcessHub` ensures that services run in separate processes, providing better isolation and resource management.
85+
- **State Management**: The hub manages the state of each service, ensuring they are running as expected and automatically restarting them when necessary.
86+
87+
### Controllers
88+
89+
Loopster includes different controllers that manage the state of services:
90+
91+
- `AlwaysForceTargetStateController`: A simple controller that always sets states in a loop.
92+
- `PanicController`: A controller that stops managing on any problem.
93+
94+
### Drivers
95+
96+
The `ProcessDriver` class is used to serve services as child processes. It provides methods for adding, removing, and setting the state of services.

docs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
wget==3.2 # AS IS, Unlicense
2-
sphinx>=1.6,<2.0 # BSD
3-
sphinxcontrib-plantuml==0.12 # BSD
2+
sphinx>=4.5,<5.0 # BSD
3+
sphinxcontrib-plantuml>=0.30,<1.0 # BSD
44
Pillow>=2.4.0 # PIL License
55
docutils<0.18 # BSD
66
reno==3.2.0 # Apache-2.0

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
77
Welcome to loopster's documentation!
8-
===================================
8+
====================================
99

1010
Loopster - Service library
1111

0 commit comments

Comments
 (0)