buffer-trigger 0.3.0

A data collection trigger based on the maximum number and refresh time
Documentation

Other language versions

简体中文

Introduction

A data collection trigger based on the maximum number and refresh time.

scenes to be used:

  • Aggregate logs, output regularly and quantitatively.
  • Aggregate large amounts of MQ data and merge processing.
  • For a large number of update requests, you can update the cache first, and then merge and refresh the db.
  • ...All operations that require aggregation, throttling, etc. can be used.

Basic usage

see tests

#[macro_use]
extern crate lazy_static;
use buffer_trigger::{BufferTrigger, SimpleBufferTrigger, SimpleBufferTriggerBuilder};
use log::LevelFilter;
use std::{thread, time::Duration};

lazy_static! {
    static ref BUFFER_TRIGGER: SimpleBufferTrigger<i32, Vec<i32>> =
        SimpleBufferTriggerBuilder::<i32, Vec<i32>>::builder(Vec::default)
            .name("test".to_owned())
            .accumulator(|c, e| c.push(e))
            .consumer(|c| log::info!("{:?}", c))
            .max_len(3)
            .interval(Duration::from_millis(500))
            .build();
}

#[test]
fn it_works() {
    let _ = env_logger::builder()
        .is_test(true)
        .filter_level(LevelFilter::Debug)
        .try_init();

    thread::spawn(|| {
        BUFFER_TRIGGER.listen_clock_trigger();
    });

    BUFFER_TRIGGER.push(1);
    BUFFER_TRIGGER.push(2);
    BUFFER_TRIGGER.push(3);
    BUFFER_TRIGGER.push(4);
    BUFFER_TRIGGER.push(5);

    thread::sleep(Duration::from_secs(5));
}

output:

[1, 2, 3]
[4, 5]

Features

This project is still under development. The following features with the check marks are supported.

If you are concerned about an unimplemented feature, please tell me and I will finish writing it ASAP.

  • Trigger timing based on quantity
  • Trigger based on delay timing (each element can be stored in the container for the maximum time)
  • Various types of containers
    • Local container storage
    • Remote Container Storage (redis)
  • You can specify the asynchronous version of runtime
    • async-std
    • tokio

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions