# Fourier job worker (#25) — systemd --user unit.
#
# The worker is a SEPARATE long-lived process from the API container: it claims
# pending jobs and runs the heavy engines (separate/sources/loops). Runs as a
# systemd --user service with lingering on, so it survives logout and starts at
# boot (see memory reference_durable_background_jobs — harness/nohup jobs die on
# teardown; systemd --user is the durable path).
#
# Install on the deploy host (the box that runs the audio service):
#   loginctl enable-linger $USER
#   cp deploy/fourier-worker.service ~/.config/systemd/user/
#   systemctl --user daemon-reload
#   systemctl --user enable --now fourier-worker
#   journalctl --user -u fourier-worker -f
#
# NOTE: the worker needs the SAME env as the API (FOURIER_DB, FOURIER_CACHE,
# engine venv). Point WorkingDirectory + EnvironmentFile at the deployed copy.
# If the API runs containerized via `nechapi ship`, either run this worker on the
# host against a shared DB/cache volume, or add it as a second process in the
# image — a paved-road decision (see SRE.md / #34).

[Unit]
Description=Fourier audio-API job worker
After=network.target

[Service]
Type=simple
WorkingDirectory=%h/srv/fourier/api
EnvironmentFile=%h/.config/fourier/fourier.env
ExecStart=%h/.virtualenvs/fourier/bin/python -m worker
Restart=on-failure
RestartSec=3
# graceful: the worker traps SIGTERM, finishes the current job's bookkeeping, exits
KillSignal=SIGTERM
TimeoutStopSec=120

[Install]
WantedBy=default.target
