Skip to main content

main

Function main 

Source
pub(crate) fn main() -> Result<(), Box<dyn Error + Send + Sync>>
Expand description

Starts the archiver service and reacts to configuration updates.

Startup, in order:

  1. Quarantines unfinished files under PARQUET_DIR (see quarantine_incomplete_files).
  2. Connects to local NATS with NATS_CREDS_FILE and opens (or creates) the config KV bucket.
  3. If central mirroring is configured, copies the central config once (a failure is logged, not fatal) and later starts run_central_kv_sync in the background.
  4. Loads the config from CFG_KEY and starts one writer per enabled channel with spawn_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_secs changed, 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.