amoorion.daemon.base

Daemon: runs services side by side until one ends or it is stopped.

A service is anything long-running: the API (which also receives the hooks) and a NATS subscriber now; platform listeners (Discord, Telegram, Matrix bots) later. When one service ends or fails, the others are stopped.

Functions

serve(args)

Run the daemon until stopped: amoorion daemon.

services(host, port)

The API always; NATS when .env names its server.

Classes

ApiService(host, port)

The HTTP API with its hooks, as a service of the daemon.

Daemon(services)

Runs the services together; when one ends, all are stopped.

Service([view])

One long-running part of the daemon.

class amoorion.daemon.base.Service(view=None)[source]

Bases: Controller

One long-running part of the daemon. It runs until stopped; see Daemon.

Parameters:

view (View | None)

async run()[source]

Work until stopped; returning or raising ends the whole daemon.

Return type:

None

async stop()[source]

Ask the service to end; run should return soon after.

Return type:

None

class amoorion.daemon.base.ApiService(host, port)[source]

Bases: Service

The HTTP API with its hooks, as a service of the daemon.

Parameters:
  • host (str)

  • port (int)

async run()[source]

Serve until stop is called.

Return type:

None

async stop()[source]

Ask the server to finish what it is doing and exit.

Return type:

None

class amoorion.daemon.base.Daemon(services)[source]

Bases: Controller

Runs the services together; when one ends, all are stopped.

A half-working daemon is worse than a stopped one, as something restarts it from outside (systemd, a container).

Parameters:

services (list[Service])

async run()[source]

Start every service, wait for the first to end, stop the rest, raise its failure if any.

Return type:

None

amoorion.daemon.base.services(host, port)[source]

The API always; NATS when .env names its server.

Parameters:
  • host (str)

  • port (int)

Return type:

list[Service]

amoorion.daemon.base.serve(args)[source]

Run the daemon until stopped: amoorion daemon.

Parameters:

args (Namespace)

Return type:

None