Struct cron_tab::Cron

source ·
pub struct Cron<Z>where
    Z: TimeZone + Sync + Send + 'static,
    Z::Offset: Send,{ /* private fields */ }

Implementations§

source§

impl<Z> Cron<Z>where Z: TimeZone + Sync + Send + 'static, Z::Offset: Send,

Cron contains and executes the scheduled jobs.

source

pub fn new(tz: Z) -> Cron<Z>

Create a new cron.

let mut cron = cron::Cron::new(Utc);
cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();    
Examples found in repository?
examples/simple.rs (line 6)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    let local_tz = Local::from_offset(&FixedOffset::east(7));
    let mut cron = cron_tab::Cron::new(local_tz);

    let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();

    // start cron in background
    cron.start();

    cron.add_fn("* * * * * *", move || {
        println!("add_fn {}", Local::now().to_string());
    })
    .unwrap();

    // remove job_test
    cron.remove(first_job_id);

    std::thread::sleep(std::time::Duration::from_secs(10));

    // stop cron
    cron.stop();
}
source

pub fn add_fn<T>(&mut self, spec: &str, f: T) -> Result<usize>where T: 'static + Fn() + Send + Sync,

Add a function to Cron.

let mut cron = cron::Cron::new(Utc);
cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();    
Examples found in repository?
examples/simple.rs (line 8)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    let local_tz = Local::from_offset(&FixedOffset::east(7));
    let mut cron = cron_tab::Cron::new(local_tz);

    let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();

    // start cron in background
    cron.start();

    cron.add_fn("* * * * * *", move || {
        println!("add_fn {}", Local::now().to_string());
    })
    .unwrap();

    // remove job_test
    cron.remove(first_job_id);

    std::thread::sleep(std::time::Duration::from_secs(10));

    // stop cron
    cron.stop();
}
source

pub fn set_timezone(&mut self, tz: Z)

Set timezone offset.

let mut cron = cron::Cron::new(Utc);
cron.start();    
source

pub fn remove(&self, id: usize)

Remove a job from Cron.

let mut cron = cron::Cron::new();
let job_id = cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();  
cron.remove(job_id);  
Examples found in repository?
examples/simple.rs (line 19)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    let local_tz = Local::from_offset(&FixedOffset::east(7));
    let mut cron = cron_tab::Cron::new(local_tz);

    let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();

    // start cron in background
    cron.start();

    cron.add_fn("* * * * * *", move || {
        println!("add_fn {}", Local::now().to_string());
    })
    .unwrap();

    // remove job_test
    cron.remove(first_job_id);

    std::thread::sleep(std::time::Duration::from_secs(10));

    // stop cron
    cron.stop();
}
source

pub fn stop(&self)

Stop Cron.

let mut cron = cron::Cron::new();
let job_id = cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();  
cron.stop();  
Examples found in repository?
examples/simple.rs (line 24)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    let local_tz = Local::from_offset(&FixedOffset::east(7));
    let mut cron = cron_tab::Cron::new(local_tz);

    let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();

    // start cron in background
    cron.start();

    cron.add_fn("* * * * * *", move || {
        println!("add_fn {}", Local::now().to_string());
    })
    .unwrap();

    // remove job_test
    cron.remove(first_job_id);

    std::thread::sleep(std::time::Duration::from_secs(10));

    // stop cron
    cron.stop();
}
source

pub fn start(&mut self)

Start cron. A thead will be spawn for schedule jobs

let mut cron = cron::Cron::new(Utc);
let job_id = cron.add_fn("* * * * * *", || {
println!("anonymous fn");
}).unwrap();
cron.start();
Examples found in repository?
examples/simple.rs (line 11)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    let local_tz = Local::from_offset(&FixedOffset::east(7));
    let mut cron = cron_tab::Cron::new(local_tz);

    let first_job_id = cron.add_fn("* * * * * * *", print_now).unwrap();

    // start cron in background
    cron.start();

    cron.add_fn("* * * * * *", move || {
        println!("add_fn {}", Local::now().to_string());
    })
    .unwrap();

    // remove job_test
    cron.remove(first_job_id);

    std::thread::sleep(std::time::Duration::from_secs(10));

    // stop cron
    cron.stop();
}
source

pub fn start_blocking(&mut self)

Run a loop for schedule jobs

Trait Implementations§

source§

impl<Z> Clone for Cron<Z>where Z: TimeZone + Sync + Send + 'static + Clone, Z::Offset: Send,

source§

fn clone(&self) -> Cron<Z>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Z> RefUnwindSafe for Cron<Z>where Z: RefUnwindSafe,

§

impl<Z> Send for Cron<Z>

§

impl<Z> Sync for Cron<Z>

§

impl<Z> Unpin for Cron<Z>where Z: Unpin,

§

impl<Z> UnwindSafe for Cron<Z>where Z: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.