persistent_scheduler::core::store

Trait TaskStore

Source
pub trait TaskStore: Clone + Send {
    type Error: Error + Send + Sync;

    // Required methods
    fn restore_tasks<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        task_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<TaskMeta>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskMeta>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn store_task<'life0, 'async_trait>(
        &'life0 self,
        task: TaskMeta,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn store_tasks<'life0, 'async_trait>(
        &'life0 self,
        tasks: Vec<TaskMeta>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn fetch_pending_tasks<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskMeta>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn update_task_execution_status<'life0, 'life1, 'async_trait>(
        &'life0 self,
        task_id: &'life1 str,
        is_success: bool,
        last_error: Option<String>,
        next_run: Option<i64>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn heartbeat<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        task_id: &'life1 str,
        runner_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn set_task_stopped<'life0, 'life1, 'async_trait>(
        &'life0 self,
        task_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn set_task_removed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        task_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn cleanup<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}

Required Associated Types§

Required Methods§

Source

fn restore_tasks<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Restores task states by cleaning up all tasks in a running state and handling their next run times.

This method performs the following actions:

  • Cleans up all tasks that are currently in the Running state and may handle their next_run fields.
  • Additional restoration logic can be added within this method.
§Returns

Returns a Result, which is Ok(()) if the operation succeeds; otherwise, it returns the appropriate error.

§Examples
Source

fn get<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskMeta>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves task metadata based on the task ID.

§Arguments
  • task_id: A unique identifier for the task.
§Returns

Returns an Option<TaskMetaEntity>. If the task is found, it returns Some(TaskMetaEntity), otherwise it returns None.

Source

fn list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskMeta>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists all task metadata.

§Returns

Returns a vector containing all task metadata.

Source

fn store_task<'life0, 'async_trait>( &'life0 self, task: TaskMeta, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores task metadata.

§Arguments
  • task: The task metadata to be stored.
§Returns

Returns Ok(()) if the task is successfully stored; returns an error if the task ID already exists.

Source

fn store_tasks<'life0, 'async_trait>( &'life0 self, tasks: Vec<TaskMeta>, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores tasks metadata.

§Arguments
  • tasks: The task metadata to be stored.
§Returns

Returns Ok(()) if the tasks is successfully stored; returns an error if any task ID already exists.

Source

fn fetch_pending_tasks<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskMeta>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetches all pending tasks from the store.

§Returns

Returns a Result containing a Vec<TaskMeta> if successful, or an error of type Self::Error if fetching tasks fails.

The returned Vec<TaskMeta> contains all tasks that are currently in a pending state, ready for processing.

§Errors

This function will return an error of type Self::Error if there is an issue querying the task store.

Source

fn update_task_execution_status<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, is_success: bool, last_error: Option<String>, next_run: Option<i64>, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Updates the execution status of a task.

§Arguments
  • task_id: The ID of the task to update.
  • is_success: A boolean indicating whether the task succeeded.
  • last_error: An optional string containing the last error message (if applicable).
  • next_run: An optional timestamp for the next scheduled run of the task.
§Returns

Returns Ok(()) if the update is successful; returns an error if the task is not found or if it is stopped or removed.

Source

fn heartbeat<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task_id: &'life1 str, runner_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Updates the heartbeat for a task.

§Arguments
  • task_id: The ID of the task to update.
  • runner_id: The ID of the runner that is currently executing the task.
§Returns

Returns Ok(()) if the update is successful; returns an error if the task is not found.

Source

fn set_task_stopped<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Marks a task as stopped.

§Arguments
  • task_id: The ID of the task to mark as stopped.
§Returns

Returns Ok(()) if the task is successfully marked; returns an error if the task is not found.

Source

fn set_task_removed<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Marks a task as removed.

§Arguments
  • task_id: The ID of the task to mark as removed.
§Returns

Returns Ok(()) if the task is successfully marked; returns an error if the task is not found.

Source

fn cleanup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cleans up the task store by removing tasks marked as removed.

§Returns

Returns Ok(()) if the cleanup is successful.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§