Git Product home page Git Product logo

crony's Introduction

Crates.io

crony

crony = "0.2.1"

Crony: a simple cron runner

Use the Job trait to create your cron job struct, pass it to the Runner and then start it via run() method. Runner will spawn new thread where it will start looping through the jobs and will run their handle method once the scheduled time is reached.

If your OS has enough threads to spare each job will get its own thread to execute, if not it will be executed in the same thread as the loop but will hold the loop until the job is finished.

Please look at the Job trait documentation for more information.

Example

extern crate crony;

use crony::{Job, Runner, Schedule};
use std::str::FromStr;

struct ExampleJob;
impl Job for ExampleJob {
    fn schedule(&self) -> Schedule {
        // Runs every minute
        Schedule::from_str("0 * * * * *").unwrap()
    }
    fn handle(&self) {
        println!("Hello, I am cron job running at: {}", self.now());
    }
}

fn main() {
    println!("Hello world");
    Runner::new().add(Box::new(ExampleJob)).run();
}

/*
Hello world
Hello, I am cron job running at: 2020-12-10 16:01:59.740944 UTC
Hello, I am cron job running at: 2020-12-10 16:02:59.821043 UTC
*/

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.

crony's People

Contributors

dbajramo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.