Service¶
-
class
binp.service.
Info
(**data)[source]¶ Service information
-
autostart
: bool¶ is service marked to be started automatically
-
description
: str¶ service description
-
name
: str¶ service name
-
restart
: bool¶ is service has to be restarted automatically
-
restart_delay
: float¶ interval between restarts
-
status
: binp.service.Status¶ actual service status
-
-
class
binp.service.
Service
[source]¶ Annotate async function as service (background task). Supports automatic (default) and manual start, restarts, restarts delays.
Useful to interact with environment in unpredictable schedule (ex: listen for low-level network requests).
from binp import BINP from asyncio import sleep binp = BINP() @binp.service async def check_messages(): while True: await sleep(3) print("checks")
For scheduling by time better use aiocron instead:
pip install aiocron
from binp import BINP from aiocron import crontab binp = BINP() @crontab("*/5 * * * *") @binp.journal async def poll_something(): print("do something every 5 minutes....")
- Conflicts
- Services are indexed by name. If multiple services defined with the same name - the old one will be stopped and
the latest one will be used.
- Events
service_changed
- when service status changed. Emits Info