#trigger #buffer #numbers #maximum #data #refresh #container

buffer-trigger

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

7 releases (breaking)

0.7.0 Jan 6, 2021
0.6.0 Aug 15, 2020
0.5.0 Aug 4, 2020
0.4.0 Aug 3, 2020
0.1.0 Aug 1, 2020

#1883 in Algorithms

23 downloads per month

MIT/Apache

31KB
788 lines

Buffer Trigger

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


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

more see tests

#[macro_use]
extern crate lazy_static;
use buffer_trigger::{
    self, buffer_trigger_sync, buffer_trigger_sync::BufferTrigger,
};
use std::{thread, time::Duration};

lazy_static! {
    static ref SIMPLE_BUFFER_TRIGGER: buffer_trigger_sync::Simple<i32, Vec<i32>> =
        buffer_trigger_sync::SimpleBuilder::builder(Vec::default)
            .name("test".to_owned())
            .accumulator(|c, e| c.push(e))
            .consumer(|c| log::info!("{:?}", c))
            .max_len(15)
            .interval(Duration::from_millis(500))
            .build();
}
#[test]
fn simple_test() {
    let _ = env_logger::builder()
        .is_test(true)
        .filter_level(LevelFilter::Debug)
        .try_init();

    for i in 0..100 {
        SIMPLE_BUFFER_TRIGGER.push(i);
    }

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

output:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
[15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
[30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44]
[45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]
[60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74]
[75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89]
[90, 91, 92, 93, 94, 95, 96, 97, 98, 99]

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)
  • Different runtime
    • sync (Multithreading)
    • tokio
  • Multiple type versions
    • general (You can use it to implement remote/local services, such as redis.)
    • simple (local service)
    • reids (remote service demo)

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

Dependencies

~8–20MB
~262K SLoC