Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure #1

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{
handler::SkedgyHandler,
scheduler::{SkedgyState, SkedgyTask},
};

pub(crate) enum SkedgyCommand<T: SkedgyHandler> {
Add(SkedgyTask<T>),
Remove(String),
Update(SkedgyTask<T>),
GetState(async_channel::Sender<SkedgyState<T>>),
LoadState(SkedgyState<T>),
}
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::time::Duration;

/// Configuration for the `Skedgy` scheduler.
#[derive(Debug, Clone)]
pub struct SkedgyConfig {
pub tick_interval: Duration,
}
3 changes: 3 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub trait SkedgyContext: Clone {}

impl<T: Clone> SkedgyContext for T {}
27 changes: 27 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::error::Error;

/// Errors that can occur during scheduling or running tasks with the `Skedgy` scheduler.
#[derive(Debug)]
pub enum SkedgyError {
/// Error sending a message to the scheduler.
SendError,
/// Error receiving a message from the scheduler.
RecvError,
/// An invalid cron expression was provided.
InvalidCron,
/// An error occurred during a scheduler tick.
TickError,
}

impl Error for SkedgyError {}

impl std::fmt::Display for SkedgyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SkedgyError::SendError => write!(f, "Error sending message to scheduler"),
SkedgyError::RecvError => write!(f, "Error receiving message from scheduler"),
SkedgyError::InvalidCron => write!(f, "Invalid cron expression"),
SkedgyError::TickError => write!(f, "Error during scheduler tick"),
}
}
}
8 changes: 8 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::context::SkedgyContext;

/// A trait for defining task handlers that can be scheduled by the `Skedgy` scheduler.
/// Implement this trait for your task handler and define the task's behavior in the `handle` method.
pub trait SkedgyHandler: Clone + Send + Sync + 'static {
type Context: SkedgyContext + Send + Sync + 'static;
fn handle(&self, ctx: Self::Context) -> impl std::future::Future<Output = ()> + Send;
}
Loading