Skip to main content

BatchUploader

Struct BatchUploader 

Source
pub struct BatchUploader {
    pub buffer: Arc<Mutex<Vec<Sample>>>,
    shutdown: Arc<AtomicBool>,
    upload_interval_secs: u64,
    sample_interval_secs: u64,
}

Fields§

§buffer: Arc<Mutex<Vec<Sample>>>

Buffer shared with the main thread.

§shutdown: Arc<AtomicBool>

Set to true by request_shutdown() to trigger a final flush.

§upload_interval_secs: u64

Polling interval for the upload thread (seconds, default 60).

§sample_interval_secs: u64

Sampling interval (seconds) – needed to compute per-interval byte counts in CSV.

Implementations§

Source§

impl BatchUploader

Source

pub fn new( upload_interval_secs: u64, sample_interval_secs: u64, ) -> (Self, Arc<Mutex<Vec<Sample>>>)

Create a new BatchUploader and return the shared SampleBuffer so the main thread can push samples into it.

Source

pub fn shutdown_flag(&self) -> Arc<AtomicBool>

Clone the shutdown flag so main.rs can signal the upload thread to flush and exit after moving self into the spawned thread.

Source

pub fn spawn( self, ctx: Arc<Mutex<RunContext>>, agent: Agent, api_base: String, token: String, ) -> JoinHandle<Vec<String>>

Spawn the background upload thread.

The thread wakes every upload_interval_secs, drains the buffer, builds a .csv.gz batch (gzip-compressed CSV, Content-Type: application/gzip), and uploads it to S3. On shutdown signal it performs one final flush before exiting.

Returns a JoinHandle<Vec<String>> whose value is the list of all successfully uploaded S3 URIs (e.g. "s3://bucket/prefix/run-id/000000.csv.gz"). The caller uses this list to decide the /finish route:

  • non-empty → data_source: "s3" with data_uris
  • empty → data_source: "inline" with data_csv

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.