Skip to content

Commit

Permalink
README and moving each backend to separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
pxp9 committed Apr 12, 2024
1 parent a468938 commit 27ea179
Show file tree
Hide file tree
Showing 7 changed files with 731 additions and 615 deletions.
2 changes: 1 addition & 1 deletion fang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typed-builder = "0.14"
typetag = "0.2"
uuid = { version = "1.1", features = ["v4"] }
fang-derive-error = { version = "0.1.0" , optional = true}
sqlx = {version = "0.6.3", features = ["any" , "macros" , "runtime-tokio-rustls", "postgres", "sqlite", "mysql"], optional = true}
sqlx = {version = "0.6.3", features = ["any" , "macros" , "runtime-tokio-rustls"], optional = true}

[dependencies.diesel]
version = "2.1"
Expand Down
24 changes: 18 additions & 6 deletions fang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Fang

Background task processing library for Rust. It uses Postgres DB as a task queue.
Background task processing library for Rust. It can use PostgreSQL, SQLite or MySQL as a task queue.

## Key Features

Expand All @@ -31,32 +31,44 @@ Here are some of the fang's key features:

```toml
[dependencies]
fang = { version = "0.10.4" , features = ["blocking"], default-features = false }
fang = { version = "1.0.0" , features = ["blocking"], default-features = false }
```

#### the Asynk feature

```toml
[dependencies]
fang = { version = "0.10.4" , features = ["asynk"], default-features = false }
fang = { version = "1.0.0" , features = ["asynk"], default-features = false }
```

#### the Asynk feature with derive macro

```toml
[dependencies]
fang = { version = "0.10.4" , features = ["asynk", "derive-error" ], default-features = false }
fang = { version = "1.0.0" , features = ["asynk", "derive-error" ], default-features = false }
```

#### All features

```toml
fang = { version = "0.10.4" }
fang = { version = "1.0.0" }
```

_Supports rustc 1.62+_

2. Create the `fang_tasks` table in the Postgres database. The migration can be found in [the migrations directory](https://github.com/ayrat555/fang/blob/master/fang/postgres_migrations/migrations/2022-08-20-151615_create_fang_tasks/up.sql).
2. Create the `fang_tasks` table in the database. The migration can be found in [the migrations directory](https://github.com/ayrat555/fang/blob/master/fang/postgres_migrations/migrations/2022-08-20-151615_create_fang_tasks/up.sql).

Migrations can be also run as code, importing the feature `migrations-{database}` being the `database` the backend queue you want to use.

```toml
[dependencies]
fang = { version = "1.0.0" , features = ["asynk-postgres", "migrations-postgres" ], default-features = false }
```

```rust
use fang::run_migrations_postgres;
run_migrations_postgres(&mut connection).unwrap();
```

## Usage

Expand Down
21 changes: 14 additions & 7 deletions fang/src/asynk/async_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ use std::env;

use super::backend_sqlx::BackendSqlX;

fn get_backend(_anykind: AnyKind) -> BackendSqlX {
match _anykind {
#[cfg(feature = "asynk-postgres")]
AnyKind::Postgres => BackendSqlX::Pg,
#[cfg(feature = "asynk-mysql")]
AnyKind::MySql => BackendSqlX::MySql,
#[cfg(feature = "asynk-sqlite")]
AnyKind::Sqlite => BackendSqlX::Sqlite,
#[allow(unreachable_patterns)]
_ => unreachable!(),
}
}

impl AsyncQueue {
/// Check if the connection with db is established
pub fn check_if_connection(&self) -> Result<(), AsyncQueueError> {
Expand All @@ -193,13 +206,7 @@ impl AsyncQueue {

let anykind = pool.any_kind();

let backend = match anykind {
AnyKind::Postgres => BackendSqlX::Pg,
AnyKind::Sqlite => BackendSqlX::Sqlite,
AnyKind::MySql => BackendSqlX::Mysql,
};

self.backend = backend;
self.backend = get_backend(anykind);

self.pool = Some(pool);
self.connected = true;
Expand Down
Loading

0 comments on commit 27ea179

Please sign in to comment.