pub(crate) fn main() -> Result<(), Box<dyn Error + Send + Sync>>Expand description
Starts the archiver service and reacts to configuration updates.
Startup, in order:
- Quarantines unfinished files under
PARQUET_DIR(seequarantine_incomplete_files). - Connects to local NATS with
NATS_CREDS_FILEand opens (or creates) the config KV bucket. - If central mirroring is configured, copies the central config once (a failure is
logged, not fatal) and later starts
run_central_kv_syncin the background. - Loads the config from
CFG_KEYand starts one writer per enabled channel withspawn_channel_logger.
It then loops until Ctrl-C or the end of the KV watch:
- Every 5 seconds it restarts any channel whose writer task has finished or is missing (for example after a consumer error or a failed start).
- On a KV put it parses the new config (invalid values are logged and ignored),
stops writers for removed channels, restarts writers whose subject, stream,
consumer name, asset or
rotate_secschanged, sends calibration-only changes to the running writer, and starts writers for new channels. Delete and purge events are ignored.
On exit it stops every writer, which closes its file and acks its messages.
ยงErrors
Returns an error if NATS_SERVERS is invalid, if quarantining fails, if the
credentials cannot be loaded or the NATS connection fails, if the KV bucket cannot
be opened or created, if the central server list is invalid, if the config key is
missing or does not parse, if the KV watch cannot be started, if any initial channel
writer fails to start, or if listening for Ctrl-C fails.