-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Restructure * clippy * restructure
- Loading branch information
Showing
13 changed files
with
567 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub trait SkedgyContext: Clone {} | ||
|
||
impl<T: Clone> SkedgyContext for T {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.