``
_______ ___
___ ________ ____ __/_ __(_)_ _ ___ ____/ _ \
/ _
/ / _ `/ _ \/ -) / / / ' \/ -) _/ , _/
_, // _,/ ./_// /////_// //||
/_/ // grapeTimerR
A coarse-grained time scheduler can help you create time tasks quickly and simply through some series.
一款粗粒度的时间调度器,可以帮你通过一些字符串快速并简单的创建时间任务。
grapeTimer的Rust版本,提供相同功能以及相同类型的服务。
std::chrono::Datetime
(Created by date format)[需要提前指定]
(Controllable scheduler time granularity [Need to specify in advance]
)[支持每天、每周、每月]
(Time period, multi-mode controllable number of times [support daily, weekly, monthly]
)[Chrono Datetime]
(Can get the string of the next execution time)[自生成ID请注意并发场景下的线程争抢]
(Custom TimerId generation trait [Self-generated ID, please pay attention to thread contention in concurrent scenarios]
)The scheduler has a light date pattern analysis system, which can provide daily, weekly, and monthly time and date generation methods
调度器有轻度的日期模式分析体系,可提供每日,每周,每月的时间日期生成方式,具体格式如下:
|关键字 Key|格式 Format |说明 Description| |:----------:|:-------:|:----------:| |Day|Day 00:00:00|生成每日的日期时间| |Week|Week 1 00:00:00|生成每周的日期时间, 0~6 分别代表周日到周六 | |Month|Month 1 00:00:00|生成每月该日期的时间,建议不要使用28日之后的日期|
|Key|Format |Description| |:----------:|:-------:|:----------:| |Day|Day 00:00:00|Generate daily date and time| |Week|Week 1 00:00:00|Generate weekly date and time, 0~6 represent Sunday to Saturday| |Month|Month 1 00:00:00|The time when the date of the month was generated, it is recommended not to use the date after the 28th|
parser date format
```rust use grapeTimerR::parsers; // get next tick Datetime let nextday = parsers::parsernext("Day 05::00:00").unwrap(); // get next timestamp let nextdayTime = parsers::parsertimestamp("Day 05::00:00").unwrap();
// utc let nextdayUtc = parsers::parsernextUtc("Day 05::00:00").unwrap(); let nextdayTimeUtc = parsers::parsertimestampUtc("Day 05::00:00").unwrap(); ```
init system
```rust use grapeTimerR::{timer::Config,IDMode, timer};
let conf = Config{ // output log info debug: true, debuglog:String::from("logs/grapeTimer.log"), threadcount: 10, // 初始化全局ID的起始ID,可以自行控制 // Initialize the starting ID of the global ID, which can be controlled by yourself idseed: 1, idtype: IDMode::SequenceId };
timer::init_schedule(conf); ```
add ticker
rust
fn executer_task(id:u64) {
println!("on function mode:{}",chrono::Local::now().to_rfc2822());
}
// 使用函数方式执行代码 Use function to execute code
timer::spwan_ticker(time::Duration::from_millis(5000),2,executer_task);
// 使用闭包模式 Use closure function
timer::spwan_ticker(time::Duration::from_millis(5000),2,|x| {
println!("on ticker:{}",chrono::Local::now().to_rfc2822());
});
add ticker by trait mode
```rust struct ExempleAction {}
// 首先我们定义一个结构体 //First we define a struct impl TaskAction for ExempleAction { // 实际执行的代码段 // Code snippet executed fn execute(&self, id: u64) { println!("on trait struct:{}",chrono::Local::now().to_rfc2822()); }
// 不使用的话,返回一个空字符串
// If not used, return an empty string,like ""
fn date_format(&self) -> &str {
return ""
}
// 如果你不使用date_format,就必须使用这个参数,否则异常。
// If you don't use date_format, you must use this parameter, otherwise it is panic.
// 时间单位 毫秒 ,time unit is millisecond
fn tick(&self) -> u64 {
return 5000;
}
// 这里需要自定义ID或将其设置为一个组的ID,所以停止任务会停止这个组
// Here you need to customize the ID or set it to the GroupId or TaskType Id,
// so stopping the task will stop the group
fn id(&self) -> u64 {
return 18888;
}
// 循环的次数
fn loop_count(&self) -> i32 {
return 15;
}
}
// 使用trait任务,可以简化部分实际逻辑
// Using trait tasks can simplify part of the actual logic
timer::spwan_trait(Arc::new(ExempleAction{}));
```
add date
rust
timer::spwan_date("day 19:21:50",1,|id| {
println!("on date:{}",chrono::Local::now().to_rfc2822());
});
Use Jetbrains Ide for project