Skip to content

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

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

liangyongrui/buffer-trigger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages