Skip to main content

spawn_channel_logger

Function spawn_channel_logger 

Source
pub(crate) async fn spawn_channel_logger(
    js: Context,
    stream_name: String,
    consumer_name: String,
    subject: String,
    asset: u32,
    channel: u8,
    rotate_secs: u64,
    calibration: CalibrationSpec,
    parquet_root: PathBuf,
    state_dir: Option<PathBuf>,
) -> Result<ChannelLogger, Box<dyn Error + Send + Sync>>
Expand description

Starts the durable pull consumer and writer task for one channel.

The returned ChannelLogger lets the config watcher update calibration metadata or gracefully stop and respawn the task when identity changes.

The consumer is created with archiver_consumer_config if it does not exist. An existing consumer whose ack_wait or max_ack_pending differs is updated in place. An existing consumer that filters on a different subject is left alone, and the consumer named by filtered_consumer_name is used instead.

Messages at or below the replay-guard checkpoint are acked without being written (see ReplayState), and the checkpoint is refreshed from the consumer’s ack floor every CHECKPOINT_INTERVAL and when the task ends.

The spawned task reads messages and writes them with process_scan_payload, holding each message unacked until its file is closed. It closes the open file and settles its messages (see close_and_settle) when:

  • MAX_PENDING_ACKS_PER_FILE messages are waiting,
  • no data has arrived for IDLE_CLOSE_AFTER (checked every IDLE_CHECK_INTERVAL),
  • a different calibration arrives, so the next file carries the new metadata,
  • the task ends because of a stop request, a consumer error, the end of the message stream, or the calibration sender being dropped.

If attaching the message stream fails, the task logs the error and ends at once. A panic inside the task (for example an output directory that cannot be created) also ends it. In both cases main sees the task as finished and restarts the channel on its next health check.

§Arguments

  • js - Local JetStream context.
  • stream_name - Stream that holds the channel subject.
  • consumer_name - Durable consumer name, from archiver_consumer_name.
  • subject - Channel subject to filter on.
  • asset - Asset number for output paths.
  • channel - LabJack channel number.
  • rotate_secs - Rotation window length in seconds.
  • calibration - Initial calibration for the channel.
  • parquet_root - Root output directory.
  • state_dir - Directory for replay-guard checkpoints (see ReplayState); None turns the guard off.

§Errors

Returns an error if the stream cannot be found, or the consumer cannot be created, fetched or updated.