Crate quartz

Source
Expand description

§Quartz Scheduler

This is a Rust port of the Quartz Scheduler originally written in Java. Quartz can be integrated within pretty much any Rust application that targets a multithreaded architecture.

§High level architecture

A Scheduler runs off a main scheduler thread that will dispatch Jobs for execution to workers from a thread pool, which is configurable. The dispatch occurs based off a Trigger defining the actual schedule for a Job to fire.

§Examples

Basic usage example showing how to set up a simple job and trigger within the Quartz scheduler:

use quartz::{Scheduler, Job, Trigger};

// Create a new scheduler instance
let scheduler = Scheduler::new();

// Define a job with an `id`, `group` and a function to execute
let job = Job::with_identity(
    "basic_job",
    "default_group",
    || println!("Executing the basic job!")
);

// Create a trigger with an identifier and a group
// to execute immediately and repeat twice, every 200ms
let trigger = Trigger::with_identity("basic_trigger", "default_group")
    .repeat(2)
    .every(std::time::Duration::from_millis(200));

// Schedule the job using the trigger
scheduler.schedule_job(job, trigger);

// Note: this example assumes the scheduler implementation is handling
// job executions based on its triggers appropriately in the background.
// Give it some time to execute
std::thread::sleep(std::time::Duration::from_secs(1));

// finally shutting the scheduler down
scheduler.shutdown();

Structs§

Job
Describes “what” is to be executed
Scheduler
Entry point in Quartz, which also controls the lifecycle of the necessary resources. The Scheduler is the entry point of the Quartz Scheduler, responsible for managing the lifecycle of scheduling resources and orchestrating the execution of tasks.
SchedulerBuilder
A builder for configuring and constructing a Scheduler instance.
Trigger
Describes the schedule to use when scheduling Jobs with a Scheduler