Use slices where possible

This commit is contained in:
Rafael Caricio 2023-03-11 22:33:25 +01:00
parent 89df4cfe8e
commit eed21d265d
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
4 changed files with 7 additions and 7 deletions

View file

@ -23,12 +23,12 @@ impl Default for RetentionMode {
} }
} }
pub use queue::Queue;
pub use runnable::BackgroundTask; pub use runnable::BackgroundTask;
pub use store::{PgTaskStore, TaskStore}; pub use store::{PgTaskStore, TaskStore};
pub use task::{CurrentTask, Task, TaskId, TaskState}; pub use task::{CurrentTask, Task, TaskId, TaskState};
pub use worker_pool::WorkerPool;
pub use worker::Worker; pub use worker::Worker;
pub use queue::Queue; pub use worker_pool::WorkerPool;
pub mod errors; pub mod errors;
mod queries; mod queries;

View file

@ -65,7 +65,7 @@ impl Task {
pub(crate) async fn fetch_next_pending( pub(crate) async fn fetch_next_pending(
connection: &mut AsyncPgConnection, connection: &mut AsyncPgConnection,
queue_name: &str, queue_name: &str,
task_names: &Vec<String>, task_names: &[String],
) -> Option<Task> { ) -> Option<Task> {
backie_tasks::table backie_tasks::table
.filter(backie_tasks::task_name.eq_any(task_names)) .filter(backie_tasks::task_name.eq_any(task_names))

View file

@ -22,7 +22,7 @@ impl TaskStore for PgTaskStore {
async fn pull_next_task( async fn pull_next_task(
&self, &self,
queue_name: &str, queue_name: &str,
task_names: &Vec<String>, task_names: &[String],
) -> Result<Option<Task>, AsyncQueueError> { ) -> Result<Option<Task>, AsyncQueueError> {
let mut connection = self let mut connection = self
.pool .pool
@ -114,7 +114,7 @@ pub mod test_store {
async fn pull_next_task( async fn pull_next_task(
&self, &self,
queue_name: &str, queue_name: &str,
task_names: &Vec<String>, task_names: &[String],
) -> Result<Option<Task>, AsyncQueueError> { ) -> Result<Option<Task>, AsyncQueueError> {
let mut tasks = self.tasks.lock().await; let mut tasks = self.tasks.lock().await;
let mut next_task = None; let mut next_task = None;
@ -201,7 +201,7 @@ pub trait TaskStore: Clone + Send + Sync + 'static {
async fn pull_next_task( async fn pull_next_task(
&self, &self,
queue_name: &str, queue_name: &str,
task_names: &Vec<String>, task_names: &[String],
) -> Result<Option<Task>, AsyncQueueError>; ) -> Result<Option<Task>, AsyncQueueError>;
async fn create_task(&self, new_task: NewTask) -> Result<Task, AsyncQueueError>; async fn create_task(&self, new_task: NewTask) -> Result<Task, AsyncQueueError>;
async fn set_task_state(&self, id: TaskId, state: TaskState) -> Result<(), AsyncQueueError>; async fn set_task_state(&self, id: TaskId, state: TaskState) -> Result<(), AsyncQueueError>;

View file

@ -91,7 +91,7 @@ where
} }
pub(crate) async fn run_tasks(&mut self) -> Result<(), BackieError> { pub(crate) async fn run_tasks(&mut self) -> Result<(), BackieError> {
let registered_task_names = self.task_registry.keys().cloned().collect(); let registered_task_names = self.task_registry.keys().cloned().collect::<Vec<_>>();
loop { loop {
// Check if has to stop before pulling next task // Check if has to stop before pulling next task
if let Some(ref shutdown) = self.shutdown { if let Some(ref shutdown) = self.shutdown {