Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite and MySql support for asynk #141

Merged
merged 91 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
2eb4b48
possible impl with sqlx, we need to refactor dependencies and feature…
pxp9 Aug 26, 2023
1a09371
fix clippy xd
pxp9 Aug 26, 2023
cbe2d99
finally sqlite almost work, need help to debug something
pxp9 Aug 28, 2023
63b39c3
deleting some expects
pxp9 Aug 28, 2023
fb7d4ba
sqlite may work in workflow
pxp9 Aug 28, 2023
2ff47e1
stupid workflow work
pxp9 Aug 29, 2023
fdbe924
plz work
pxp9 Aug 29, 2023
20f376a
plz work , think i have fixed
pxp9 Aug 29, 2023
e79c0ee
fix workflow , now will work :D
pxp9 Aug 29, 2023
7e1ac88
this should work
Dopplerian Aug 29, 2023
4f308f2
this will definitely work
Dopplerian Aug 29, 2023
204a38a
clean up so it works incorrectly faster
Dopplerian Aug 29, 2023
fdb4f1e
okay that didn't work so idk what i'm doing here
Dopplerian Aug 29, 2023
5ba9910
if this works i'm dropping out of university
Dopplerian Aug 29, 2023
5119dcf
store uuid as text , so this way `PostgreSQL` schema will not change
pxp9 Aug 29, 2023
168b476
fix comment
pxp9 Aug 29, 2023
f4459d9
fix clippy
pxp9 Aug 29, 2023
bf53cfa
implement backend sqlx trait that allows better code
pxp9 Aug 29, 2023
0040820
better implementation with enum variants
pxp9 Aug 30, 2023
d6eb6e5
Merge branch 'master' into support-sqlite-mysql-asynk
Dopplerian Aug 31, 2023
08238bc
`Makefile` now creates `tests_sqlite` directory
Dopplerian Aug 31, 2023
169d955
make `asynk` tests use `.env` variables
Dopplerian Aug 31, 2023
4589673
drop unnecessary `drop`
Dopplerian Aug 31, 2023
a11ef55
query types as enum
pxp9 Sep 1, 2023
3332c83
fix clippy
pxp9 Sep 1, 2023
5f1c601
fix fmt, my bad i had a missconf in my home computer xd
pxp9 Sep 1, 2023
67bf9d0
stupid mysql does not work anything , i hate it so much :/
pxp9 Sep 1, 2023
fa4f135
rework to make it work with MySQL
pxp9 Sep 2, 2023
16e94ef
debugging issue : the issue is related to how a uniq task is inserted…
pxp9 Sep 2, 2023
eaa7bc0
MySQL own mutex , why Mysql is so gae ?
pxp9 Sep 2, 2023
f3a14d4
fix clippy
ayrat555 Sep 8, 2023
c57b0ba
split test jobs
ayrat555 Sep 8, 2023
b5deaed
fix build
ayrat555 Sep 8, 2023
9ffbf51
fix github actions
ayrat555 Sep 8, 2023
f8a87fd
do not run github actions twice
ayrat555 Sep 8, 2023
5592b09
fix formatting build
ayrat555 Sep 8, 2023
1bbe5ef
another approach
ayrat555 Sep 8, 2023
0501322
tokio console debug
pxp9 Apr 8, 2024
56c2dc9
fixing workflow
pxp9 Apr 8, 2024
c35cc3b
fixing workflow again
pxp9 Apr 8, 2024
218dd3b
i think i finally fixed
pxp9 Apr 8, 2024
f09c8e6
fixed \!
pxp9 Apr 8, 2024
8dd0c89
fixed \?
pxp9 Apr 8, 2024
c17740b
i am stupid now should be fixed :)
pxp9 Apr 8, 2024
d6f95fc
test blocking and fang derive error
pxp9 Apr 8, 2024
847a281
add postgres service to blocking workflow
pxp9 Apr 8, 2024
8230d9a
running async worker tests and blocking worker tests
pxp9 Apr 8, 2024
0a23009
cargo term color sqlite
pxp9 Apr 8, 2024
cc792ab
change sqlx version to 0.6.3 and using Pool instead of Transactions
pxp9 Apr 9, 2024
262d5d6
fix workflow for mysql
pxp9 Apr 9, 2024
41584c7
fix workflow
pxp9 Apr 9, 2024
4b0bdad
fix clippy, warns and mysql workflow
pxp9 Apr 9, 2024
192722d
adress comments and fix workflow
pxp9 Apr 9, 2024
db93dbb
fix mysql healthcheck
pxp9 Apr 9, 2024
32905b2
fix mysql healthcheck, yeap again
pxp9 Apr 9, 2024
2b30c0a
remove healthcheck
pxp9 Apr 9, 2024
9f0c74d
healthcheck is needed , plz work
pxp9 Apr 9, 2024
5ed857f
plz just work :(
pxp9 Apr 9, 2024
330539a
try to fix workflow
ayrat555 Apr 12, 2024
db904e6
update workflow to use a non deprecated version
pxp9 Apr 12, 2024
e31296d
return an error instead of panicking with fock
pxp9 Apr 12, 2024
6f85163
deleting prints and updating comments
pxp9 Apr 12, 2024
a468938
deleting unwraps or justifying them
pxp9 Apr 12, 2024
27ea179
README and moving each backend to separate files
pxp9 Apr 12, 2024
46540db
final README
pxp9 Apr 12, 2024
665ac47
bump fang version and bump rust version
pxp9 Apr 12, 2024
bd1e1a8
nit: added missing newline for consistency
Dopplerian Apr 13, 2024
a291459
update readme
Dopplerian Apr 13, 2024
108d55c
bump fang version following semver
Dopplerian Apr 13, 2024
0e59175
address ayrat issues
pxp9 Apr 14, 2024
7ec0e79
Fix/independent decoding (#149)
pxp9 Apr 15, 2024
890531a
relocate comment
Dopplerian Apr 15, 2024
fe69c66
remove `backend` field from `AsyncQueue`
Dopplerian Apr 15, 2024
201bc3b
fix clippy
Dopplerian Apr 15, 2024
9f540b7
worst clippy fix of all time
Dopplerian Apr 15, 2024
0dd461f
fmt fix
Dopplerian Apr 15, 2024
edf744a
use variant NoBackend instead Option
pxp9 Apr 15, 2024
f0ae9fe
fix clippy
pxp9 Apr 15, 2024
ce47e61
delete dummy variant
pxp9 Apr 15, 2024
baef61e
changing sqlite and mysql migrations
pxp9 Apr 15, 2024
527868b
sqlx uuid encoding and decoding for sqlite and postgres
pxp9 Apr 16, 2024
0f0be07
delete uuid previous impl comment
pxp9 Apr 16, 2024
c611d60
fix retry_task impl
pxp9 Apr 16, 2024
45d896a
fix mysql timestamp precision
pxp9 Apr 17, 2024
ea85604
rework encoding Datime<Utc> for postgresql and sqlite
pxp9 Apr 17, 2024
94fd332
rework encoding Uuid for mysql
pxp9 Apr 17, 2024
9da8548
fix clippy
pxp9 Apr 17, 2024
aafb352
fix serde_json::Value decoding and encoding
pxp9 Apr 17, 2024
e7c15bb
README stuff
pxp9 Apr 17, 2024
af8e0b4
improving API
pxp9 Apr 18, 2024
adff5b2
improving worker API
pxp9 Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/rust.yml
pxp9 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,29 @@ jobs:
command: clippy
args: --verbose --all-targets --all-features -- -D warnings

- name: Install sqlite3
run: |
sudo apt install -y sqlite3
sqlite3 fang.db "VACUUM;"
mkdir tests_sqlite

- name: Install diesel-cli
uses: actions-rs/cargo@v1
with:
command: install
args: diesel_cli --no-default-features --features "postgres"
args: diesel_cli --no-default-features --features "postgres sqlite mysql"

- name: Setup Sqlite db
pxp9 marked this conversation as resolved.
Show resolved Hide resolved
working-directory: ./fang/sqlite_migrations
run: diesel setup --database-url "sqlite3://../../../fang.db"

- name: Change working dir
working-directory: ./../..
run: pwd

- name: Setup Postgres db
working-directory: ./fang/postgres_migrations
run: diesel setup
run: diesel setup --database-url "postgres://postgres:postgres@localhost/fang"

- name: Change working dir
working-directory: ./../..
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/schema.rs
docs/content/docs/CHANGELOG.md
docs/content/docs/README.md
fang.db
tests_sqlite/
38 changes: 19 additions & 19 deletions fang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@ rust-version = "1.62"
doctest = false

[features]
default = ["blocking", "asynk", "derive-error", "postgres", "mysql" , "sqlite", "migrations_postgres", "migrations_sqlite" , "migrations_mysql"]
blocking = ["dep:diesel", "dep:diesel-derive-enum", "dep:dotenvy", "diesel?/chrono" , "diesel?/serde_json" , "diesel?/uuid"]
asynk = ["dep:bb8-postgres", "dep:postgres-types", "dep:tokio", "dep:async-trait", "dep:async-recursion"]
default = ["blocking", "asynk-sqlx", "derive-error", "blocking-postgres", "blocking-mysql" , "blocking-sqlite", "migrations-postgres", "migrations-sqlite" , "migrations-mysql"]
asynk-postgres = ["asynk-sqlx" , "sqlx?/postgres"]
asynk-sqlite = ["asynk-sqlx" , "sqlx?/sqlite"]
asynk-mysql = ["asynk-sqlx" , "sqlx?/mysql"]
asynk-sqlx = ["asynk" , "dep:sqlx"]
asynk = ["dep:tokio", "dep:async-trait", "dep:async-recursion" ]
derive-error = ["dep:fang-derive-error"]
postgres = ["diesel?/postgres" , "diesel?/serde_json", "diesel?/chrono" , "diesel?/uuid" , "diesel?/r2d2"]
sqlite = ["diesel?/sqlite" , "diesel?/serde_json", "diesel?/chrono" , "diesel?/uuid" , "diesel?/r2d2"]
mysql = ["diesel?/mysql" , "diesel?/serde_json", "diesel?/chrono" , "diesel?/uuid" , "diesel?/r2d2"]
migrations_postgres = ["migrations"]
migrations_sqlite = ["migrations"]
migrations_mysql = ["migrations"]
blocking = ["dep:diesel", "dep:diesel-derive-enum", "dep:dotenvy", "diesel?/chrono" , "diesel?/serde_json" , "diesel?/uuid", "diesel?/r2d2"]
blocking-postgres = [ "blocking", "diesel?/postgres"]
blocking-sqlite = ["blocking", "diesel?/sqlite" ]
blocking-mysql = [ "blocking", "diesel?/mysql"]
migrations-postgres = ["migrations"]
migrations-sqlite = ["migrations"]
migrations-mysql = ["migrations"]
pxp9 marked this conversation as resolved.
Show resolved Hide resolved
migrations = ["dep:diesel_migrations"]


[dev-dependencies]
fang-derive-error = { version = "0.1.0"}
diesel_migrations = { version = "2.1" , features = ["postgres", "sqlite" , "mysql"]}
sqlx = {git = "https://github.com/pxp9/sqlx", branch = "main", features = ["any" , "macros" , "runtime-tokio", "postgres", "sqlite", "mysql"]}
Dopplerian marked this conversation as resolved.
Show resolved Hide resolved


[dependencies]
cron = "0.12"
Expand All @@ -46,6 +52,10 @@ typed-builder = "0.14"
typetag = "0.2"
uuid = { version = "1.1", features = ["v4"] }
fang-derive-error = { version = "0.1.0" , optional = true}
# sqlx with no TLS, if you want TLS you must to get feature "tls-native-tls" or "tls-rustls"
#sqlx = {version = "0.7", features = ["any" , "macros" , "json" , "uuid" , "chrono" , "runtime-tokio", "postgres", "sqlite", "mysql"] }
# https://github.com/launchbadge/sqlx/issues/2416 is fixed in pxp9's fork
sqlx = {git = "https://github.com/pxp9/sqlx", branch = "main", features = ["any" , "macros" , "runtime-tokio"] , optional = true}

[dependencies.diesel]
version = "2.1"
Expand All @@ -61,16 +71,6 @@ optional = true
version = "0.15"
optional = true

[dependencies.bb8-postgres]
version = "0.8"
features = ["with-serde_json-1" , "with-uuid-1" , "with-chrono-0_4"]
optional = true

[dependencies.postgres-types]
version = "0.X.X"
features = ["derive"]
optional = true

[dependencies.tokio]
version = "1.25"
features = ["rt", "time", "macros"]
Expand Down
2 changes: 1 addition & 1 deletion fang/fang_examples/asynk/simple_async_worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fang = { path = "../../../" , features = ["asynk", "postgres"]}
fang = { path = "../../../" , features = ["asynk-postgres", "migrations-postgres"]}
env_logger = "0.9.0"
log = "0.4.0"
dotenvy = "0.15"
Expand Down
5 changes: 2 additions & 3 deletions fang/fang_examples/asynk/simple_async_worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use fang::asynk::async_queue::AsyncQueueable;
use fang::asynk::async_worker_pool::AsyncWorkerPool;
use fang::run_migrations_postgres;
use fang::AsyncRunnable;
use fang::NoTls;
use simple_async_worker::MyFailingTask;
use simple_async_worker::MyTask;
use std::env;
Expand Down Expand Up @@ -36,10 +35,10 @@ async fn main() {
.max_pool_size(max_pool_size)
.build();

queue.connect(NoTls).await.unwrap();
queue.connect().await.unwrap();
log::info!("Queue connected...");

let mut pool: AsyncWorkerPool<AsyncQueue<NoTls>> = AsyncWorkerPool::builder()
let mut pool: AsyncWorkerPool<AsyncQueue> = AsyncWorkerPool::builder()
.number_of_workers(10_u32)
.queue(queue.clone())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fang = { path = "../../../" , features = ["asynk"]}
fang = { path = "../../../" , features = ["asynk-postgres"]}
env_logger = "0.9.0"
log = "0.4.0"
dotenvy = "0.15"
Expand Down
5 changes: 2 additions & 3 deletions fang/fang_examples/asynk/simple_cron_async_worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use fang::asynk::async_queue::AsyncQueue;
use fang::asynk::async_queue::AsyncQueueable;
use fang::asynk::async_worker_pool::AsyncWorkerPool;
use fang::AsyncRunnable;
use fang::NoTls;
use simple_cron_async_worker::MyCronTask;
use std::env;
use std::time::Duration;
Expand All @@ -21,10 +20,10 @@ async fn main() {
.max_pool_size(max_pool_size)
.build();

queue.connect(NoTls).await.unwrap();
queue.connect().await.unwrap();
log::info!("Queue connected...");

let mut pool: AsyncWorkerPool<AsyncQueue<NoTls>> = AsyncWorkerPool::builder()
let mut pool: AsyncWorkerPool<AsyncQueue> = AsyncWorkerPool::builder()
.number_of_workers(10_u32)
.queue(queue.clone())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE fang_task_state AS ENUM ('new', 'in_progress', 'failed', 'finished', 'retried');

CREATE TABLE fang_tasks (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
id BYTEA PRIMARY KEY,
pxp9 marked this conversation as resolved.
Show resolved Hide resolved
metadata jsonb NOT NULL,
error_message TEXT,
state fang_task_state DEFAULT 'new' NOT NULL,
task_type VARCHAR DEFAULT 'common' NOT NULL,
uniq_hash CHAR(64),
task_type TEXT DEFAULT 'common' NOT NULL,
uniq_hash TEXT, -- just for compatibility with sqlx is text
retries INTEGER DEFAULT 0 NOT NULL,
scheduled_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
-- docker exec -ti mysql mysql -u root -pfang -P 3360 fang -e "$(catn fang/mysql_migrations/migrations/2023-08-17-102017_create_fang_tasks/up.sql)"

CREATE TABLE fang_tasks (
id TEXT CHECK (LENGTH(id) = 36) NOT NULL PRIMARY KEY, -- UUID generated inside the language
-- why uuid is a text ? https://stackoverflow.com/questions/17277735/using-uuids-in-sqlite
id BLOB NOT NULL PRIMARY KEY, -- UUID generated inside the language
-- why uuid is a blob ? https://stackoverflow.com/questions/17277735/using-uuids-in-sqlite
metadata TEXT NOT NULL,
-- why metadata is text ? https://stackoverflow.com/questions/16603621/how-to-store-json-object-in-sqlite-database#16603687
error_message TEXT,
Expand All @@ -16,10 +16,10 @@ CREATE TABLE fang_tasks (
retries INTEGER NOT NULL DEFAULT 0,
-- The datetime() function returns the date and time as text in this formats: YYYY-MM-DD HH:MM:SS.
-- https://www.sqlite.org/lang_datefunc.html
scheduled_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
scheduled_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP || '.000000+00'),
-- why timestamps are texts ? https://www.sqlite.org/datatype3.html
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
created_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP || '.000000+00'),
updated_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP || '.000000+00')
);

CREATE INDEX fang_tasks_state_index ON fang_tasks(state);
Expand Down
Loading
Loading