pub trait Queueable {
    // Required methods
    fn fetch_and_touch_task(
        &self,
        task_type: String
    ) -> Result<Option<Task>, QueueError>;
    fn insert_task(&self, params: &dyn Runnable) -> Result<Task, QueueError>;
    fn remove_all_tasks(&self) -> Result<usize, QueueError>;
    fn remove_all_scheduled_tasks(&self) -> Result<usize, QueueError>;
    fn remove_tasks_of_type(&self, task_type: &str) -> Result<usize, QueueError>;
    fn remove_task(&self, id: Uuid) -> Result<usize, QueueError>;
    fn remove_task_by_metadata(
        &self,
        task: &dyn Runnable
    ) -> Result<usize, QueueError>;
    fn find_task_by_id(&self, id: Uuid) -> Option<Task>;
    fn update_task_state(
        &self,
        task: &Task,
        state: FangTaskState
    ) -> Result<Task, QueueError>;
    fn fail_task(&self, task: &Task, error: &str) -> Result<Task, QueueError>;
    fn schedule_task(&self, task: &dyn Runnable) -> Result<Task, QueueError>;
    fn schedule_retry(
        &self,
        task: &Task,
        backoff_in_seconds: u32,
        error: &str
    ) -> Result<Task, QueueError>;
}
Expand description

This trait defines operations for a synchronous queue. The trait can be implemented for different storage backends. For now, the trait is only implemented for PostgreSQL. More backends are planned to be implemented in the future.

Required Methods§

source

fn fetch_and_touch_task( &self, task_type: String ) -> Result<Option<Task>, QueueError>

This method should retrieve one task of the task_type type. After fetching it should update the state of the task to FangTaskState::InProgress.

source

fn insert_task(&self, params: &dyn Runnable) -> Result<Task, QueueError>

Enqueue a task to the queue, The task will be executed as soon as possible by the worker of the same type created by an WorkerPool.

source

fn remove_all_tasks(&self) -> Result<usize, QueueError>

The method will remove all tasks from the queue

source

fn remove_all_scheduled_tasks(&self) -> Result<usize, QueueError>

Remove all tasks that are scheduled in the future.

source

fn remove_tasks_of_type(&self, task_type: &str) -> Result<usize, QueueError>

Removes all tasks that have the specified task_type.

source

fn remove_task(&self, id: Uuid) -> Result<usize, QueueError>

Remove a task by its id.

source

fn remove_task_by_metadata( &self, task: &dyn Runnable ) -> Result<usize, QueueError>

To use this function task has to be uniq. uniq() has to return true. If task is not uniq this function will not do anything. Remove a task by its metadata (struct fields values)

source

fn find_task_by_id(&self, id: Uuid) -> Option<Task>

source

fn update_task_state( &self, task: &Task, state: FangTaskState ) -> Result<Task, QueueError>

Update the state field of the specified task See the FangTaskState enum for possible states.

source

fn fail_task(&self, task: &Task, error: &str) -> Result<Task, QueueError>

Update the state of a task to FangTaskState::Failed and set an error_message.

source

fn schedule_task(&self, task: &dyn Runnable) -> Result<Task, QueueError>

Schedule a task.

source

fn schedule_retry( &self, task: &Task, backoff_in_seconds: u32, error: &str ) -> Result<Task, QueueError>

Implementors§