Metadata-Version: 2.4
Name: scietex.vacuum_gauge_service
Version: 0.1.4
Summary: Scietex microservice daemon for vacuum gauge monitoring
Author-email: Anton Bondarenko <bond.anton@gmail.com>
License-Expression: MIT
Project-URL: Bug Tracker, https://github.com/bond-anton/scietex.vacuum_gauge_service/issues
Project-URL: Homepage, https://github.com/bond-anton/scietex.vacuum_gauge_service
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: scietex.service[valkey]~=6.1.1
Requires-Dist: scietex.hal.vacuum_gauge<3.0.0,>=2.0.0
Requires-Dist: pymodbus~=3.15
Provides-Extra: dev
Requires-Dist: tox>=4.45.0; extra == "dev"
Provides-Extra: lint
Requires-Dist: ruff; extra == "lint"
Requires-Dist: ty; extra == "lint"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-asyncio; extra == "test"
Dynamic: license-file

# scietex.vacuum_gauge_service

**scietex.vacuum_gauge_service** is a `scietex.service` worker that monitors one
or more Modbus/TCP vacuum gauges through the Scietex Modbus gateway. Each gauge
is polled through a [`scietex.hal.vacuum_gauge`](https://github.com/bond-anton/scietex.hal.vacuum_gauge)
driver selected by dotted path, and the per-gauge readings are published to
Valkey. The service accepts monitoring commands and per-gauge control commands
through the framework's task-handler channel.

The worker is a long-running daemon. It seeds its in-memory gauge list from
`vacuum_gauge.yml` at startup and updates it from the framework's remote-config
channel at runtime.

**Python ≥ 3.10** · **License: MIT**

## Configuration

The service reads `vacuum_gauge.yml` from a `vacuum_gauge/` subdirectory of its
config directory. When the file is missing, the service generates a default on
first run:

```yaml
gateway:
  host: 127.0.0.1
  port: 502
  timeout: 1.0
gauges: []
```

| Setting | Default | Meaning |
| --- | --- | --- |
| `gateway.host` | `127.0.0.1` | Modbus gateway TCP host |
| `gateway.port` | `502` | Modbus gateway TCP port |
| `gateway.timeout` | `1.0` | Per-transaction timeout, seconds |
| `gauges` | `[]` | Monitored gauge list |

Each gauge entry:

| Field | Default | Meaning |
| --- | --- | --- |
| `label` | — (required) | Human-readable gauge name |
| `driver` | — (required) | Dotted path to a `scietex.hal.vacuum_gauge` gauge class |
| `unit_id` | `1` | Modbus unit id on the gateway bus |
| `poll_interval` | `1.0` | Poll period, seconds |

## Running

```bash
start-vacuum-gauge-service --conf-dir /etc/scietex
```

`--conf-dir` defaults to the framework's auto-resolved config directory when
omitted. The service runs in the foreground until it receives `SIGINT` or
`SIGTERM`.

Environment variables:

| Variable | Meaning |
| --- | --- |
| `SCIETEX_SERVICE_NAME` | Service name |
| `SCIETEX_LOGGING_LEVEL` | Logging level |

## Container image

The `Containerfile` is a two-stage build on `python:3.14-slim-trixie`:

- **Builder stage** installs the released `scietex.vacuum_gauge_service` wheel
  from PyPI (selected by the `VERSION` build arg) and its dependencies into
  `/opt/venv`, then slims the venv (drops pip/setuptools/wheel, bytecode caches,
  and the unused per-interpreter `glide_shared` extensions).
- **Runtime stage** copies the venv, creates a non-root `appuser` (uid 1000),
  prepares `/config`, and runs `start-vacuum-gauge-service`.

The image installs the published package rather than building from the local
checkout, so the image and the PyPI artifact for a given version are the same
code. The `VERSION` build arg must name a version that exists on PyPI.

The service reaches gauges over Modbus/TCP through a gateway, so the container
needs no serial devices and no privileged ports.

The image sets these defaults:

```dockerfile
ENV SCIETEX_CONFIG_DIR=/config \
    SCIETEX_SERVICE_NAME=VacuumGaugeService \
    SCIETEX_LOGGING_LEVEL=INFO
VOLUME ["/config"]
```

### Build

```bash
podman build --build-arg VERSION=0.1.1 -t scietex-vacuum-gauge-service .
```

`build_image.sh` builds a multi-arch manifest (`linux/amd64,linux/arm64`) and
pushes it to `registry.buro-nts.ru/scietex-vacuum-gauge-service`, tagged with the
version from `version.py`. It passes that version as the `VERSION` build arg, so
the image always installs the matching PyPI release. Pass `--latest` to also
push the `latest` tag.

### Run

```bash
podman run --rm \
  -v scietex-config:/config \
  -e SCIETEX_SERVICE_NAME=VacuumGaugeService \
  scietex-vacuum-gauge-service:0.1.1
```

The gateway address and gauge list come from the API domain plugin, which
publishes them to Valkey; `vacuum_gauge.yml` under the config volume only seeds
the initial values.

## Development

Dependencies are managed with **uv**; checks and tests run through **tox**:

```bash
uv sync --all-extras
uv run tox
```
