fix Error struct export for asynk (#61)

* fix Error struct export for `asynk`

* fix imports in tests

* bump version
This commit is contained in:
Ayrat Badykov 2022-08-05 10:06:32 +03:00 committed by GitHub
parent 3f8b189f90
commit 2bf660c9ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 21 deletions

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.7.1 (2022-08-04)
- Fix a conflict in exports of the `blocking` and the `asynk` features - [#61](https://github.com/ayrat555/fang/pull/61)
## 0.7.0 (2022-08-03) ## 0.7.0 (2022-08-03)
### [#21](https://github.com/ayrat555/fang/pull/21) ### [#21](https://github.com/ayrat555/fang/pull/21)

View file

@ -1,6 +1,6 @@
[package] [package]
name = "fang" name = "fang"
version = "0.7.0" version = "0.7.1"
authors = ["Ayrat Badykov <ayratin555@gmail.com>" , "Pepe Márquez <pepe.marquezromero@gmail.com>"] authors = ["Ayrat Badykov <ayratin555@gmail.com>" , "Pepe Márquez <pepe.marquezromero@gmail.com>"]
description = "Background job processing library for Rust" description = "Background job processing library for Rust"
repository = "https://github.com/ayrat555/fang" repository = "https://github.com/ayrat555/fang"
@ -46,7 +46,6 @@ version = "0.8"
features = ["with-serde_json-1" , "with-uuid-0_8" , "with-chrono-0_4"] features = ["with-serde_json-1" , "with-uuid-0_8" , "with-chrono-0_4"]
optional = true optional = true
[dependencies.postgres-types] [dependencies.postgres-types]
version = "0.X.X" version = "0.X.X"
features = ["derive"] features = ["derive"]

View file

@ -18,14 +18,20 @@ Background task processing library for Rust. It uses Postgres DB as a task queue
#### Blocking feature #### Blocking feature
```toml ```toml
[dependencies] [dependencies]
fang = { version = "0.7" , features = ["blocking"]} fang = { version = "0.7" , features = ["blocking"], default-features = false }
``` ```
#### Asynk feature #### Asynk feature
```toml ```toml
[dependencies] [dependencies]
fang = { version = "0.7" , features = ["asynk"]} fang = { version = "0.7" , features = ["asynk"], default-features = false }
``` ```
#### Both features
```toml
fang = { version = "0.7" }
```
*Supports rustc 1.62+* *Supports rustc 1.62+*
2. Create `fang_tasks` table in the Postgres database. The migration can be found in [the migrations directory](https://github.com/ayrat555/fang/blob/master/migrations/2021-06-05-112912_create_fang_tasks/up.sql). 2. Create `fang_tasks` table in the Postgres database. The migration can be found in [the migrations directory](https://github.com/ayrat555/fang/blob/master/migrations/2021-06-05-112912_create_fang_tasks/up.sql).

View file

@ -1,11 +1,9 @@
use crate::asynk::async_runnable::AsyncRunnable;
use crate::asynk::async_runnable::Error as FangError; use crate::asynk::async_runnable::Error as FangError;
use crate::AsyncRunnable;
use async_trait::async_trait; use async_trait::async_trait;
use bb8_postgres::bb8::Pool; use bb8_postgres::bb8::Pool;
use bb8_postgres::bb8::RunError; use bb8_postgres::bb8::RunError;
use bb8_postgres::tokio_postgres::row::Row; use bb8_postgres::tokio_postgres::row::Row;
#[cfg(test)]
use bb8_postgres::tokio_postgres::tls::NoTls;
use bb8_postgres::tokio_postgres::tls::{MakeTlsConnect, TlsConnect}; use bb8_postgres::tokio_postgres::tls::{MakeTlsConnect, TlsConnect};
use bb8_postgres::tokio_postgres::Socket; use bb8_postgres::tokio_postgres::Socket;
use bb8_postgres::tokio_postgres::Transaction; use bb8_postgres::tokio_postgres::Transaction;
@ -18,6 +16,9 @@ use thiserror::Error;
use typed_builder::TypedBuilder; use typed_builder::TypedBuilder;
use uuid::Uuid; use uuid::Uuid;
#[cfg(test)]
use bb8_postgres::tokio_postgres::tls::NoTls;
const INSERT_TASK_QUERY: &str = include_str!("queries/insert_task.sql"); const INSERT_TASK_QUERY: &str = include_str!("queries/insert_task.sql");
const INSERT_PERIODIC_TASK_QUERY: &str = include_str!("queries/insert_periodic_task.sql"); const INSERT_PERIODIC_TASK_QUERY: &str = include_str!("queries/insert_periodic_task.sql");
const SCHEDULE_NEXT_TASK_QUERY: &str = include_str!("queries/schedule_next_task.sql"); const SCHEDULE_NEXT_TASK_QUERY: &str = include_str!("queries/schedule_next_task.sql");
@ -333,6 +334,7 @@ impl AsyncQueueable for AsyncQueueTest<'_> {
Ok(task) Ok(task)
} }
} }
impl<Tls> AsyncQueue<Tls> impl<Tls> AsyncQueue<Tls>
where where
Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static, Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
@ -463,6 +465,7 @@ where
let task = Self::row_to_task(row); let task = Self::row_to_task(row);
Ok(task) Ok(task)
} }
async fn schedule_next_task_query( async fn schedule_next_task_query(
transaction: &mut Transaction<'_>, transaction: &mut Transaction<'_>,
periodic_task: PeriodicTask, periodic_task: PeriodicTask,
@ -477,6 +480,7 @@ where
let periodic_task = Self::row_to_periodic_task(row); let periodic_task = Self::row_to_periodic_task(row);
Ok(periodic_task) Ok(periodic_task)
} }
async fn insert_periodic_task_query( async fn insert_periodic_task_query(
transaction: &mut Transaction<'_>, transaction: &mut Transaction<'_>,
metadata: serde_json::Value, metadata: serde_json::Value,
@ -516,6 +520,7 @@ where
Ok(Some(periodic_tasks)) Ok(Some(periodic_tasks))
} }
} }
async fn execute_query( async fn execute_query(
transaction: &mut Transaction<'_>, transaction: &mut Transaction<'_>,
query: &str, query: &str,
@ -545,6 +550,7 @@ where
None => Self::insert_task_query(transaction, metadata, task_type).await, None => Self::insert_task_query(transaction, metadata, task_type).await,
} }
} }
async fn find_task_by_metadata_query( async fn find_task_by_metadata_query(
transaction: &mut Transaction<'_>, transaction: &mut Transaction<'_>,
metadata: &serde_json::Value, metadata: &serde_json::Value,
@ -558,6 +564,7 @@ where
Err(_) => None, Err(_) => None,
} }
} }
fn row_to_periodic_task(row: Row) -> PeriodicTask { fn row_to_periodic_task(row: Row) -> PeriodicTask {
let id: Uuid = row.get("id"); let id: Uuid = row.get("id");
let metadata: serde_json::Value = row.get("metadata"); let metadata: serde_json::Value = row.get("metadata");
@ -578,6 +585,7 @@ where
.updated_at(updated_at) .updated_at(updated_at)
.build() .build()
} }
fn row_to_task(row: Row) -> Task { fn row_to_task(row: Row) -> Task {
let id: Uuid = row.get("id"); let id: Uuid = row.get("id");
let metadata: serde_json::Value = row.get("metadata"); let metadata: serde_json::Value = row.get("metadata");
@ -768,8 +776,8 @@ mod async_queue_tests {
use super::AsyncQueueable; use super::AsyncQueueable;
use super::FangTaskState; use super::FangTaskState;
use super::Task; use super::Task;
use crate::asynk::AsyncError as Error;
use crate::asynk::AsyncRunnable; use crate::asynk::AsyncRunnable;
use crate::asynk::Error;
use async_trait::async_trait; use async_trait::async_trait;
use bb8_postgres::bb8::Pool; use bb8_postgres::bb8::Pool;
use bb8_postgres::tokio_postgres::NoTls; use bb8_postgres::tokio_postgres::NoTls;

View file

@ -1,7 +1,7 @@
use crate::asynk::async_queue::AsyncQueueable; use crate::asynk::async_queue::AsyncQueueable;
use crate::asynk::async_queue::PeriodicTask; use crate::asynk::async_queue::PeriodicTask;
use crate::asynk::AsyncError as Error;
use crate::asynk::AsyncRunnable; use crate::asynk::AsyncRunnable;
use crate::asynk::Error;
use async_recursion::async_recursion; use async_recursion::async_recursion;
use log::error; use log::error;
use std::time::Duration; use std::time::Duration;
@ -169,8 +169,8 @@ mod async_scheduler_tests {
use crate::asynk::async_queue::AsyncQueueTest; use crate::asynk::async_queue::AsyncQueueTest;
use crate::asynk::async_queue::AsyncQueueable; use crate::asynk::async_queue::AsyncQueueable;
use crate::asynk::async_queue::PeriodicTask; use crate::asynk::async_queue::PeriodicTask;
use crate::asynk::AsyncError as Error;
use crate::asynk::AsyncRunnable; use crate::asynk::AsyncRunnable;
use crate::asynk::Error;
use async_trait::async_trait; use async_trait::async_trait;
use bb8_postgres::bb8::Pool; use bb8_postgres::bb8::Pool;
use bb8_postgres::tokio_postgres::NoTls; use bb8_postgres::tokio_postgres::NoTls;

View file

@ -3,7 +3,7 @@ use crate::asynk::async_queue::FangTaskState;
use crate::asynk::async_queue::Task; use crate::asynk::async_queue::Task;
use crate::asynk::async_queue::DEFAULT_TASK_TYPE; use crate::asynk::async_queue::DEFAULT_TASK_TYPE;
use crate::asynk::async_runnable::AsyncRunnable; use crate::asynk::async_runnable::AsyncRunnable;
use crate::asynk::Error; use crate::asynk::AsyncError as Error;
use crate::{RetentionMode, SleepParams}; use crate::{RetentionMode, SleepParams};
use log::error; use log::error;
use std::time::Duration; use std::time::Duration;
@ -216,8 +216,8 @@ mod async_worker_tests {
use crate::asynk::async_queue::AsyncQueueable; use crate::asynk::async_queue::AsyncQueueable;
use crate::asynk::async_queue::FangTaskState; use crate::asynk::async_queue::FangTaskState;
use crate::asynk::async_worker::Task; use crate::asynk::async_worker::Task;
use crate::asynk::AsyncError as Error;
use crate::asynk::AsyncRunnable; use crate::asynk::AsyncRunnable;
use crate::asynk::Error;
use crate::RetentionMode; use crate::RetentionMode;
use async_trait::async_trait; use async_trait::async_trait;
use bb8_postgres::bb8::Pool; use bb8_postgres::bb8::Pool;

View file

@ -1,6 +1,6 @@
use crate::asynk::async_queue::AsyncQueueable; use crate::asynk::async_queue::AsyncQueueable;
use crate::asynk::async_worker::AsyncWorker; use crate::asynk::async_worker::AsyncWorker;
use crate::asynk::Error; use crate::asynk::AsyncError as Error;
use crate::{RetentionMode, SleepParams}; use crate::{RetentionMode, SleepParams};
use async_recursion::async_recursion; use async_recursion::async_recursion;
use log::error; use log::error;

View file

@ -5,4 +5,4 @@ pub mod async_worker;
pub mod async_worker_pool; pub mod async_worker_pool;
pub use async_runnable::AsyncRunnable; pub use async_runnable::AsyncRunnable;
pub use async_runnable::Error; pub use async_runnable::Error as AsyncError;