cremalink.local_server_app.jobs module

This module defines and manages the background jobs for the local server. These jobs run periodically in asyncio tasks to handle keep-alive, status monitoring, and re-keying operations.

class cremalink.local_server_app.jobs.JobManager[source]

Bases: object

A simple manager for starting and stopping asyncio background tasks.

start(coro, name: str)[source]

Creates an asyncio task from a coroutine and adds it to the manager.

async stop()[source]

Cancels and cleans up all managed tasks.

async cremalink.local_server_app.jobs.monitor_job(st: LocalServerState, settings: ServerSettings, stop_event: Event)[source]

Periodically queues a request to fetch the device’s monitoring status.

async cremalink.local_server_app.jobs.nudger_job(st: LocalServerState, adapter: DeviceAdapter, settings: ServerSettings, stop_event: Event)[source]

Notifies a live session about pending commands (PUT local_reg).

notify: 1 makes the machine poll commands.json promptly, which is what drains the outgoing queue. While the session is down, registration retries are throttled to the register-timeout cadence — POST is what actually opens a session (key exchange), PUT alone cannot re-key a live or half-dead one (lodzen/cremalink#4).

Cadence follows the app (protocol.md §15, AylaLanModule): one local_reg PUT per keepalive tick with notify reflecting queue depth — not one PUT per nudger tick. The machine polls commands.json on its own ~1.3 s loop once notified, so faster PUTs cannot drain the queue any quicker (live-observed ~1 PUT/s while pending vs. the app’s ~1 PUT/10 s). A fresh PUT still goes out immediately on an enqueue edge (enqueue_seq moved — appends between standby ticks count, queue-empty sightings are not needed) so user writes keep ~1-tick latency.

async cremalink.local_server_app.jobs.session_job(state: LocalServerState, adapter: DeviceAdapter, settings: ServerSettings, stop_event: Event)[source]

Maintains the LAN session (lodzen/cremalink#4).

  • Live session → keep-alive PUT local_reg (notify: 1), then verify the machine still polls commands.json; a silent machine marks the session dead and the next tick re-registers.

  • Dead session → POST local_reg starts a new session and always triggers a key exchange; keys are only replaced inside LocalServerState.init_crypto(), never wiped beforehand — a preemptive wipe plus a no-rekey PUT is what produced the hollow sessions this job replaces.