pub struct Task { /* private fields */ }
Expand description
A scheduled task that can be executed
This struct represents a task in the scheduler, containing all the information needed to execute the task at the appropriate time and track its status.
§Fields
id
- Unique identifier for the taskname
- Human-readable name of the tasktask_name
- Name of the function being executedtask
- The actual function to executenext_run
- When the task should next executelast_run
- When the task last executedinterval
- Time between executionsstatus
- Current execution statusretries
- Number of retry attempts remainingcreated_at
- When the task was created
Implementations§
Source§impl Task
impl Task
Sourcepub fn new<F>(
name: String,
task_name: String,
task: F,
next_run: Option<DateTime<Utc>>,
interval: Option<Duration>,
retries: u32,
) -> Self
pub fn new<F>( name: String, task_name: String, task: F, next_run: Option<DateTime<Utc>>, interval: Option<Duration>, retries: u32, ) -> Self
Creates a new task with the specified parameters
§Arguments
name
- Human-readable name for the tasktask_name
- Name of the function being executedtask
- The function to executenext_run
- Optional next execution timeinterval
- Optional interval between executionsretries
- Number of retry attempts allowed
§Returns
A new Task instance configured with the provided parameters
Sourcepub async fn execute(&mut self) -> Result<(), SchedulerError>
pub async fn execute(&mut self) -> Result<(), SchedulerError>
Executes the task and updates its status
This method runs the task function and handles any errors that occur, including retry logic if configured.
§Returns
Ok(())
if the task executed successfullyErr(SchedulerError)
if the task failed and retries were exhausted
Sourcepub fn is_due(&self) -> bool
pub fn is_due(&self) -> bool
Checks if the task is due for execution
§Returns
true
if the task should be executed now, false
otherwise
Sourcepub async fn get_status(&self) -> TaskStatus
pub async fn get_status(&self) -> TaskStatus
Sourcepub fn get_task_name(&self) -> &str
pub fn get_task_name(&self) -> &str
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Task
impl !RefUnwindSafe for Task
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl !UnwindSafe for Task
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more