All Projects → BinChengZhao → delay-timer

BinChengZhao / delay-timer

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible scheduling, and dynamic add/cancel/remove is supported.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to delay-timer

croner
Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.
Stars: ✭ 169 (-34.24%)
Mutual labels:  cron, schedule, crontab, scheduling
watchman
📆 更夫(watchman)是一款可视化的定时任务配置 Web 工具,麻麻不用担心我漏掉任何更新啦!
Stars: ✭ 40 (-84.44%)
Mutual labels:  cron, schedule, crontab
Crontab
Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.
Stars: ✭ 62 (-75.88%)
Mutual labels:  cron, schedule, crontab
Crontabmanager
PHP library for GNU/Linux cron jobs management.
Stars: ✭ 113 (-56.03%)
Mutual labels:  cron, crontab
Agenda Rest
Scheduling as a Service
Stars: ✭ 93 (-63.81%)
Mutual labels:  cron, scheduling
Sleepto
An alternative to traditional task schedulers
Stars: ✭ 98 (-61.87%)
Mutual labels:  cron, schedule
Ppgo job
PPGo_Job是一款可视化的、多人多权限的、一任务多机执行的定时任务管理系统,采用golang开发,安装方便,资源消耗少,支持大并发,可同时管理多台服务器上的定时任务。
Stars: ✭ 1,152 (+348.25%)
Mutual labels:  cron, crontab
Schedule
Schedule module for Nest framework (node.js) ⏰
Stars: ✭ 137 (-46.69%)
Mutual labels:  cron, schedule
Go Quartz
Simple, zero-dependency scheduling library for Go
Stars: ✭ 118 (-54.09%)
Mutual labels:  cron, crontab
Quantum Core
⌚ Cron-like job scheduler for Elixir
Stars: ✭ 1,905 (+641.25%)
Mutual labels:  cron, crontab
Cronv
A visualizer for CRONTAB
Stars: ✭ 196 (-23.74%)
Mutual labels:  cron, crontab
Laravel Totem
Manage Your Laravel Schedule From A Web Dashboard
Stars: ✭ 1,299 (+405.45%)
Mutual labels:  cron, scheduling
Jobber
An alternative to cron, with sophisticated status-reporting and error-handling
Stars: ✭ 1,217 (+373.54%)
Mutual labels:  cron, schedule
Cronscheduler.aspnetcore
Cron Scheduler for AspNetCore 2.x/3.x or DotNetCore 2.x/3.x Self-hosted
Stars: ✭ 100 (-61.09%)
Mutual labels:  cron, scheduling
Wp Missed Schedule
Find only missed schedule posts, every 15 minutes, and republish correctly 10 items each session. The Original plugin (only this) no longer available on WordPress.org for explicit author request! Compatible with WP 2.1+ to 4.9+ and 5.0-beta3 (100.000+ installs 300.000+ downloads 2016-04-13) Please: do not install unauthorized malware cloned forked!
Stars: ✭ 69 (-73.15%)
Mutual labels:  cron, schedule
Cron
A cron expression parser in Rust
Stars: ✭ 132 (-48.64%)
Mutual labels:  cron, schedule
Cron Parser
Java Parser For Cron Expressions
Stars: ✭ 176 (-31.52%)
Mutual labels:  cron, crontab
Cronsun
A Distributed, Fault-Tolerant Cron-Style Job System.
Stars: ✭ 2,493 (+870.04%)
Mutual labels:  cron, crontab
Go Crond
⏰ Cron daemon written in golang (for eg. usage in docker images)
Stars: ✭ 59 (-77.04%)
Mutual labels:  cron, crontab
Forest
分布式任务调度平台,分布式,任务调度,schedule,scheduler
Stars: ✭ 231 (-10.12%)
Mutual labels:  cron, schedule

delay-timer

Build License Cargo Documentation

Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible, and dynamic add/cancel/remove is supported.

delay-timer is a task manager based on a time wheel algorithm, which makes it easy to manage timed tasks, or to periodically execute arbitrary tasks such as closures.

The underlying runtime is based on the optional smol and tokio, and you can build your application with either one.

The minimum-supported version of rustc is 1.56.

Except for the simple execution in a few seconds, you can also specify a specific date, such as Sunday at 4am to execute a backup task.

Supports configuration of the maximum number of parallelism of tasks.
Dynamically cancel a running task instance by means of a handle.

image

If you're looking for a distributed task scheduling platform, check out the delicate

Examples

use anyhow::Result;
use delay_timer::prelude::*;

fn main() -> Result<()> {
   // Build an DelayTimer that uses the default configuration of the Smol runtime internally.
   let delay_timer = DelayTimerBuilder::default().build();

   // Develop a print job that runs in an asynchronous cycle.
   // A chain of task instances.
   let task_instance_chain = delay_timer.insert_task(build_task_async_print()?)?;

   // Get the running instance of task 1.
   let task_instance = task_instance_chain.next_with_wait()?;

   // Cancel running task instances.
   task_instance.cancel_with_wait()?;

   // Remove task which id is 1.
   delay_timer.remove_task(1)?;

   // No new tasks are accepted; running tasks are not affected.
   delay_timer.stop_delay_timer()?;

   Ok(())
}

fn build_task_async_print() -> Result<Task, TaskError> {
   let mut task_builder = TaskBuilder::default();

   let body = || async {
       println!("create_async_fn_body!");

       Timer::after(Duration::from_secs(3)).await;

       println!("create_async_fn_body:i'success");
   };

   task_builder
       .set_task_id(1)
       .set_frequency_repeated_by_cron_str("@secondly")
       .set_maximum_parallel_runnable_num(2)
       .spawn_async_routine(body)
}

Use in asynchronous contexts.

use delay_timer::prelude::*;

use anyhow::Result;

use smol::Timer;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<()> {
   // In addition to the mixed (smol & tokio) runtime
   // You can also share a tokio runtime with delayTimer, please see api `DelayTimerBuilder::tokio_runtime` for details.

   // Build an DelayTimer that uses the default configuration of the Smol runtime internally.
   let delay_timer = DelayTimerBuilder::default().build();

   // Develop a print job that runs in an asynchronous cycle.
   let task_instance_chain = delay_timer.insert_task(build_task_async_print()?)?;

   // Get the running instance of task 1.
   let task_instance = task_instance_chain.next_with_async_wait().await?;

   // Cancel running task instances.
   task_instance.cancel_with_async_wait().await?;


   // Remove task which id is 1.
   delay_timer.remove_task(1)?;

   // No new tasks are accepted; running tasks are not affected.
   delay_timer.stop_delay_timer()
}

fn build_task_async_print() -> Result<Task, TaskError> {
   let mut task_builder = TaskBuilder::default();

   let body = || async {
       println!("create_async_fn_body!");

       Timer::after(Duration::from_secs(3)).await;

       println!("create_async_fn_body:i'success");
   };

   task_builder
       .set_task_id(1)
       .set_frequency_repeated_by_cron_str("@secondly")
       .set_maximum_parallel_runnable_num(2)
       .spawn_async_routine(body)
}

Capture the specified environment information and build the closure & task:

#[macro_use]
use delay_timer::prelude::*;

use std::sync::atomic::{
    AtomicUsize,
    Ordering::{Acquire, Release},
};
use std::sync::Arc;


let delay_timer = DelayTimer::new();
let share_num = Arc::new(AtomicUsize::new(0));
let share_num_bunshin = share_num.clone();

let body = move || {
    share_num_bunshin.fetch_add(1, Release);
};

let task = TaskBuilder::default()
    .set_frequency_count_down_by_cron_str(expression, 3)
    .set_task_id(1)
    .spawn_routine(body)?;

delay_timer.add_task(task)?;

Building customized-dynamic future tasks:

#[macro_use]
use delay_timer::prelude::*;
use hyper::{Client, Uri};

fn build_task_customized_async_task() -> Result<Task, TaskError> {
   let id = 1;
   let name = String::from("someting");
   let mut task_builder = TaskBuilder::default();

   let body = move || {
       let name_ref = name.clone();
       async move {
           async_template(id, name_ref).await.expect("Request failed.");

           sleep(Duration::from_secs(3)).await;

           println!("create_async_fn_body:i'success");
       }
   };

   task_builder
       .set_frequency_repeated_by_cron_str("0,10,15,25,50 0/1 * * Jan-Dec * 2020-2100")
       .set_task_id(5)
       .set_maximum_running_time(5)
       .spawn_async_routine(body)
}


pub async fn async_template(id: i32, name: String) -> Result<()> {
   let url = format!("https://httpbin.org/get?id={}&name={}", id, name);
   let mut res = surf::get(url).await?;
   dbg!(res.body_string().await?);

   Ok(())
}

There's a lot more in the [examples] directory.

License

Licensed under either of

To Do List

  • Support tokio Ecology.
  • Disable unwrap related methods that will panic.
  • Thread and running task quit when delayTimer drop.
  • neaten todo in code, replenish tests and benchmark.
  • batch-opration.
  • report-for-server.
  • Future upgrade of delay_timer to multi-wheel mode, different excutor handling different wheels e.g. subtract laps for one wheel, run task for one wheel.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].