From 92cf52a91fde2b34d078cd7e72829fa59011f97e Mon Sep 17 00:00:00 2001 From: Lucas Colombo Date: Tue, 23 Apr 2024 06:39:50 -0300 Subject: [PATCH 1/4] =?UTF-8?q?docs:=20=F0=9F=93=9D=20change=20readme=20lo?= =?UTF-8?q?go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/img/rustler-core-logo.svg | 13 +++++++++++++ README.md | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .github/img/rustler-core-logo.svg diff --git a/.github/img/rustler-core-logo.svg b/.github/img/rustler-core-logo.svg new file mode 100644 index 0000000..b9b99fc --- /dev/null +++ b/.github/img/rustler-core-logo.svg @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 022e55e..00106c8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+



From ff42808ad695c5dc3c30c79c48fe3b071ceb99c7 Mon Sep 17 00:00:00 2001 From: Lucas Colombo Date: Tue, 23 Apr 2024 07:16:39 -0300 Subject: [PATCH 2/4] =?UTF-8?q?docs:=20=F0=9F=93=9D=20readme=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 00106c8..a03ac57 100644 --- a/README.md +++ b/README.md @@ -5,31 +5,35 @@

-𝐫𝐮𝐬𝐭𝐥𝐞𝐫 is a web scraping service that scrapes several stock market providers for stock pricing data. It is built using the Rust programming language. +𝐫𝐮𝐬𝐭𝐥𝐞𝐫 ⫮ 𝐜𝐨𝐫𝐞 is a library that contains the core functionality for `rustler`, a web scraping service that scrapes several stock market providers for stock pricing data. It is built using the Rust programming language.




-## Framweork +## Why "rustler" -- [Tonic (grpc)](https://docs.rs/tonic/latest/tonic/index.html) -- websockets: - - [tokio-tungstenite](https://docs.rs/tokio-tungstenite/latest/tokio_tungstenite/) - - [fastwebsockets](https://crates.io/crates/fastwebsockets) - - [embedded-websocket](https://crates.io/crates/embedded-websocket) - bajo nivel - small - - [web-socket](https://crates.io/crates/web-socket) - supuestamente el mas rapido -- Rx Rust: - - [rxrust](https://crates.io/crates/rxrust) - - [another-rxrust](https://crates.io/crates/another-rxrust) parece un poco mejor +A `rustler` is a person who steals live***stock***. Well, this library is a service that collects _stock_ market data from the internet. So, it's a "_rustler_" for stock market data. -## Commands +Also, this library is built using the `Rust` programming language... so, ***rust***ler 😊 -```bash -# add a dependency to a project -cargo add {dependency} -p {project} +## What this library includes -# example -cargo add tokio-tungstenite -p gateway -``` \ No newline at end of file +This library defines the core functionality for a `rustler`. It includes the following: + +- A `Rustler` trait that defines the core functionality for a `rustler`. +- A `RustlersSvc` which orchestrates the `rustlers` at runtime, scheduling them to scrape stock pricing data between market hours. + +Apart from the above, this library also defines: + +- a database schema for storing market hours, which is used by the `RustlersSvc` to schedule the `rustlers`. +- a grpc service to interact with the rustlers database. + +> [!NOTE] +> +> This library defines a _rustler_ as a service that scrapes stock pricing data for a +> particular market. +> +> Although this library contains the core and abstract functionality for the rustlers, it doesn't include any concrete implementation for them. In other words, this library includes traits and structs that can be used to build a `rustler`). +> Actual concrete implementations for each market cannot be published for many reasons. \ No newline at end of file From 2efa346c766f2728dd12ace01a29ffae242f23eb Mon Sep 17 00:00:00 2001 From: Lucas Colombo Date: Tue, 23 Apr 2024 07:17:59 -0300 Subject: [PATCH 3/4] =?UTF-8?q?docs:=20=F0=9F=93=9D=20update=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a03ac57..cafb1ba 100644 --- a/README.md +++ b/README.md @@ -35,5 +35,6 @@ Apart from the above, this library also defines: > This library defines a _rustler_ as a service that scrapes stock pricing data for a > particular market. > -> Although this library contains the core and abstract functionality for the rustlers, it doesn't include any concrete implementation for them. In other words, this library includes traits and structs that can be used to build a `rustler`). +> Although this library contains the core and abstract functionality for the rustlers, it doesn't include any concrete implementation for them. +> > Actual concrete implementations for each market cannot be published for many reasons. \ No newline at end of file From 356c88ae461d7f19dee5ba01ace870dcff913e52 Mon Sep 17 00:00:00 2001 From: Lucas Colombo Date: Tue, 23 Apr 2024 09:40:46 -0300 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=F0=9F=94=A8=20convert=20into?= =?UTF-8?q?=20library?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/img/todo.svg | 1 + Cargo.lock | 661 +++--------------- Cargo.toml | 81 +-- README.md | 16 +- Taskfile.yaml | 2 +- check_size.py | 60 -- entities/Cargo.toml | 21 - .../binance.rs => examples/binance/mod.rs | 29 +- app/main.rs => examples/rustler.rs | 15 +- gateway/Cargo.toml | 14 - gateway/src/lib.rs | 0 grpc/Cargo.toml | 25 - {grpc => lib}/build.rs | 6 +- .../m20220101_000001_create_table_market.rs | 1 + .../m20240325_200049_create_table_ticker.rs | 1 + lib/entities/migration/mod.rs | 2 + entities/src/lib.rs => lib/entities/mod.rs | 1 + {entities/src => lib/entities}/orm/market.rs | 1 + {entities/src => lib/entities}/orm/ticker.rs | 1 + .../src => lib/entities}/services/market.rs | 6 +- .../src => lib/entities}/services/ticker.rs | 3 +- grpc/src/lib.rs => lib/grpc/mod.rs | 5 +- {grpc => lib/grpc}/proto/market.proto | 0 {grpc => lib/grpc}/proto/rustler.proto | 0 {grpc => lib/grpc}/proto/ticker.proto | 0 {grpc/src => lib/grpc}/server.rs | 13 +- {grpc/src => lib/grpc}/services/market.rs | 5 +- {grpc/src => lib/grpc}/services/ticker.rs | 5 +- lib/lib.rs | 4 + lib/rustlers/mod.rs | 6 + .../rustlers.rs => lib/rustlers/rustler.rs | 29 +- {rustlers/src => lib/rustlers}/rustlerjar.rs | 6 +- {rustlers/src => lib/rustlers}/svc.rs | 31 +- lib/socket/mod.rs | 1 + migration/Cargo.toml | 20 - migration/README.md | 41 -- migration/src/lib.rs | 21 - migration/src/main.rs | 6 - rustlers/Cargo.toml | 32 - rustlers/src/lib.rs | 3 - 40 files changed, 247 insertions(+), 928 deletions(-) create mode 100644 .github/img/todo.svg delete mode 100644 check_size.py delete mode 100644 entities/Cargo.toml rename rustlers/src/rustlers/binance.rs => examples/binance/mod.rs (67%) rename app/main.rs => examples/rustler.rs (58%) delete mode 100644 gateway/Cargo.toml delete mode 100644 gateway/src/lib.rs delete mode 100644 grpc/Cargo.toml rename {grpc => lib}/build.rs (71%) rename {migration/src => lib/entities/migration}/m20220101_000001_create_table_market.rs (98%) rename {migration/src => lib/entities/migration}/m20240325_200049_create_table_ticker.rs (97%) create mode 100644 lib/entities/migration/mod.rs rename entities/src/lib.rs => lib/entities/mod.rs (98%) rename {entities/src => lib/entities}/orm/market.rs (96%) rename {entities/src => lib/entities}/orm/ticker.rs (96%) rename {entities/src => lib/entities}/services/market.rs (83%) rename {entities/src => lib/entities}/services/ticker.rs (94%) rename grpc/src/lib.rs => lib/grpc/mod.rs (81%) rename {grpc => lib/grpc}/proto/market.proto (100%) rename {grpc => lib/grpc}/proto/rustler.proto (100%) rename {grpc => lib/grpc}/proto/ticker.proto (100%) rename {grpc/src => lib/grpc}/server.rs (79%) rename {grpc/src => lib/grpc}/services/market.rs (94%) rename {grpc/src => lib/grpc}/services/ticker.rs (94%) create mode 100644 lib/lib.rs create mode 100644 lib/rustlers/mod.rs rename rustlers/src/rustlers.rs => lib/rustlers/rustler.rs (91%) rename {rustlers/src => lib/rustlers}/rustlerjar.rs (95%) rename {rustlers/src => lib/rustlers}/svc.rs (91%) create mode 100644 lib/socket/mod.rs delete mode 100644 migration/Cargo.toml delete mode 100644 migration/README.md delete mode 100644 migration/src/lib.rs delete mode 100644 migration/src/main.rs delete mode 100644 rustlers/Cargo.toml delete mode 100644 rustlers/src/lib.rs diff --git a/.github/img/todo.svg b/.github/img/todo.svg new file mode 100644 index 0000000..7653ae4 --- /dev/null +++ b/.github/img/todo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 3e465d7..e3330ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,9 +58,9 @@ checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -127,9 +127,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "arrayvec" @@ -137,156 +137,6 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" -[[package]] -name = "async-attributes" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" -dependencies = [ - "quote", - "syn 1.0.109", -] - -[[package]] -name = "async-channel" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" -dependencies = [ - "concurrent-queue", - "event-listener 2.5.3", - "futures-core", -] - -[[package]] -name = "async-channel" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28243a43d821d11341ab73c80bed182dc015c514b951616cf79bd4af39af0c3" -dependencies = [ - "concurrent-queue", - "event-listener 5.2.0", - "event-listener-strategy 0.5.0", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-executor" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" -dependencies = [ - "async-lock 3.3.0", - "async-task", - "concurrent-queue", - "fastrand 2.0.1", - "futures-lite 2.3.0", - "slab", -] - -[[package]] -name = "async-global-executor" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" -dependencies = [ - "async-channel 2.2.0", - "async-executor", - "async-io 2.3.2", - "async-lock 3.3.0", - "blocking", - "futures-lite 2.3.0", - "once_cell", - "tokio", -] - -[[package]] -name = "async-io" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" -dependencies = [ - "async-lock 2.8.0", - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-lite 1.13.0", - "log", - "parking", - "polling 2.8.0", - "rustix 0.37.27", - "slab", - "socket2 0.4.10", - "waker-fn", -] - -[[package]] -name = "async-io" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcccb0f599cfa2f8ace422d3555572f47424da5648a4382a9dd0310ff8210884" -dependencies = [ - "async-lock 3.3.0", - "cfg-if", - "concurrent-queue", - "futures-io", - "futures-lite 2.3.0", - "parking", - "polling 3.5.0", - "rustix 0.38.32", - "slab", - "tracing", - "windows-sys 0.52.0", -] - -[[package]] -name = "async-lock" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" -dependencies = [ - "event-listener 2.5.3", -] - -[[package]] -name = "async-lock" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" -dependencies = [ - "event-listener 4.0.3", - "event-listener-strategy 0.4.0", - "pin-project-lite", -] - -[[package]] -name = "async-std" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" -dependencies = [ - "async-attributes", - "async-channel 1.9.0", - "async-global-executor", - "async-io 1.13.0", - "async-lock 2.8.0", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite 1.13.0", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - [[package]] name = "async-stream" version = "0.3.5" @@ -309,17 +159,11 @@ dependencies = [ "syn 2.0.53", ] -[[package]] -name = "async-task" -version = "4.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" - [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", @@ -335,12 +179,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" version = "1.1.0" @@ -466,27 +304,11 @@ dependencies = [ "generic-array", ] -[[package]] -name = "blocking" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" -dependencies = [ - "async-channel 2.2.0", - "async-lock 3.3.0", - "async-task", - "fastrand 2.0.1", - "futures-io", - "futures-lite 2.3.0", - "piper", - "tracing", -] - [[package]] name = "borsh" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f58b559fd6448c6e2fd0adb5720cd98a2506594cafa4737ff98c396f3e82f667" +checksum = "0901fc8eb0aca4c83be0106d6f2db17d86a08dfc2c25f0e84464bf381158add6" dependencies = [ "borsh-derive", "cfg_aliases", @@ -494,9 +316,9 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aadb5b6ccbd078890f6d7003694e33816e6b784358f18e15e7e6d9f065a57cd" +checksum = "51670c3aa053938b0ee3bd67c3817e471e626151131b934038e83c5bf8de48f5" dependencies = [ "once_cell", "proc-macro-crate", @@ -581,9 +403,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -603,9 +425,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -625,15 +447,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "concurrent-queue" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "const-oid" version = "0.9.6" @@ -667,9 +480,9 @@ dependencies = [ [[package]] name = "crc" -version = "3.0.1" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" dependencies = [ "crc-catalog", ] @@ -713,9 +526,9 @@ checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "pem-rfc7468", @@ -763,22 +576,13 @@ checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" dependencies = [ "serde", ] -[[package]] -name = "entities" -version = "0.1.0" -dependencies = [ - "eyre", - "lool", - "sea-orm", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -812,48 +616,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "event-listener" -version = "4.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - -[[package]] -name = "event-listener" -version = "5.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b5fb89194fa3cad959b833185b3063ba881dbfc7030680b314250779fb4cc91" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - -[[package]] -name = "event-listener-strategy" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" -dependencies = [ - "event-listener 4.0.3", - "pin-project-lite", -] - -[[package]] -name = "event-listener-strategy" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feedafcaa9b749175d5ac357452a9d41ea2911da598fde46ce1fe02c37751291" -dependencies = [ - "event-listener 5.2.0", - "pin-project-lite", -] - [[package]] name = "eyre" version = "0.6.12" @@ -866,18 +628,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "finl_unicode" @@ -996,34 +749,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - -[[package]] -name = "futures-lite" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" -dependencies = [ - "fastrand 2.0.1", - "futures-core", - "futures-io", - "parking", - "pin-project-lite", -] - [[package]] name = "futures-sink" version = "0.3.30" @@ -1098,35 +823,11 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "gloo-timers" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "grpc" -version = "0.1.0" -dependencies = [ - "entities", - "eyre", - "lool", - "prost", - "tonic", - "tonic-build", -] - [[package]] name = "h2" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ "bytes", "fnv", @@ -1285,7 +986,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", @@ -1374,35 +1075,6 @@ dependencies = [ "syn 2.0.53", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.12.1" @@ -1427,15 +1099,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -1468,12 +1131,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -1495,9 +1152,6 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -dependencies = [ - "value-bag", -] [[package]] name = "lool" @@ -1545,15 +1199,6 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" -[[package]] -name = "migration" -version = "0.1.0" -dependencies = [ - "async-std", - "entities", - "sea-orm-migration", -] - [[package]] name = "mime" version = "0.3.17" @@ -1588,9 +1233,9 @@ dependencies = [ [[package]] name = "multimap" -version = "0.8.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" [[package]] name = "native-tls" @@ -1743,9 +1388,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.101" +version = "0.9.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" dependencies = [ "cc", "libc", @@ -1786,12 +1431,6 @@ dependencies = [ "syn 2.0.53", ] -[[package]] -name = "parking" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1878,17 +1517,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "piper" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" -dependencies = [ - "atomic-waker", - "fastrand 2.0.1", - "futures-io", -] - [[package]] name = "pkcs1" version = "0.7.5" @@ -1916,36 +1544,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "polling" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" -dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if", - "concurrent-queue", - "libc", - "log", - "pin-project-lite", - "windows-sys 0.48.0", -] - -[[package]] -name = "polling" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24f040dee2588b4963afb4e420540439d126f73fdacf4a9c486a96d840bac3c9" -dependencies = [ - "cfg-if", - "concurrent-queue", - "pin-project-lite", - "rustix 0.38.32", - "tracing", - "windows-sys 0.52.0", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -2012,9 +1610,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" dependencies = [ "bytes", "prost-derive", @@ -2022,13 +1620,13 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2" +checksum = "80b776a1b2dc779f5ee0641f8ade0125bc1298dd41a9a0c16d8bd57b42d222b1" dependencies = [ "bytes", - "heck 0.4.1", - "itertools 0.11.0", + "heck 0.5.0", + "itertools", "log", "multimap", "once_cell", @@ -2039,17 +1637,16 @@ dependencies = [ "regex", "syn 2.0.53", "tempfile", - "which", ] [[package]] name = "prost-derive" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", - "itertools 0.11.0", + "itertools", "proc-macro2", "quote", "syn 2.0.53", @@ -2057,9 +1654,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e" +checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" dependencies = [ "prost", ] @@ -2147,7 +1744,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata 0.4.6", - "regex-syntax 0.8.2", + "regex-syntax 0.8.3", ] [[package]] @@ -2167,7 +1764,7 @@ checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax 0.8.3", ] [[package]] @@ -2178,9 +1775,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rend" @@ -2242,9 +1839,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.34.3" +version = "1.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39449a79f45e8da28c57c341891b69a183044b29518bb8f86dbac9df60bb7df" +checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" dependencies = [ "arrayvec", "borsh", @@ -2264,65 +1861,41 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.37.27" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - -[[package]] -name = "rustix" -version = "0.38.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", "libc", - "linux-raw-sys 0.4.13", + "linux-raw-sys", "windows-sys 0.52.0", ] [[package]] -name = "rustler" +name = "rustler-core" version = "0.0.0-alpha.0" -dependencies = [ - "chrono", - "dotenvy", - "entities", - "eyre", - "grpc", - "lool", - "rustlers", - "tokio", -] - -[[package]] -name = "rustlers" -version = "0.1.0" dependencies = [ "async-trait", "chrono", - "entities", + "dotenvy", "eyre", "getset", "lool", + "prost", + "sea-orm", + "sea-orm-migration", "tokio", "tokio-tungstenite", + "tonic", "tonic-build", ] [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" [[package]] name = "ryu" @@ -2512,9 +2085,9 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "security-framework" -version = "2.9.2" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -2525,9 +2098,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.1" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" dependencies = [ "core-foundation-sys", "libc", @@ -2535,18 +2108,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", @@ -2555,9 +2128,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -2626,16 +2199,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.6" @@ -2677,7 +2240,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ - "itertools 0.12.1", + "itertools", "nom", "unicode_categories", ] @@ -2710,7 +2273,7 @@ dependencies = [ "crc", "crossbeam-queue", "either", - "event-listener 2.5.3", + "event-listener", "futures-channel", "futures-core", "futures-intrusive", @@ -2915,9 +2478,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" @@ -2984,8 +2547,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", - "fastrand 2.0.1", - "rustix 0.38.32", + "fastrand", + "rustix", "windows-sys 0.52.0", ] @@ -3021,9 +2584,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", @@ -3042,9 +2605,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", @@ -3077,7 +2640,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2 0.5.6", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -3388,12 +2951,6 @@ dependencies = [ "serde", ] -[[package]] -name = "value-bag" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" - [[package]] name = "vcpkg" version = "0.2.15" @@ -3406,12 +2963,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "waker-fn" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" - [[package]] name = "want" version = "0.3.1" @@ -3458,18 +3009,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.92" @@ -3499,28 +3038,6 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix 0.38.32", -] - [[package]] name = "whoami" version = "1.5.1" @@ -3531,28 +3048,6 @@ dependencies = [ "wasite", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-core" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index d38f7a7..64f6f1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,48 +1,51 @@ [package] -name = "rustler" +name = "rustler-core" version = "0.0.0-alpha.0" edition = "2021" -description = "🤠 » single-action data extractor" +description = "🤠 » rustler-core market data extractor core functionality" authors = ["Lucas Colombo "] -publish = false +build = "lib/build.rs" -[profile.release] -strip = true -lto = true -codegen-units = 16 -opt-level = 'z' -panic = "abort" -rpath = false -overflow-checks = false -debug = 0 -debug-assertions = false - -[[bin]] -name = "rustler" -path = "app/main.rs" - -[workspace] -members = [".", "migration", "entities", "grpc", "rustlers"] - -[workspace.dependencies] -lool = { version = "0.2.0", registry = "lugit" } # crates: disable-check -eyre = { version = "0.6.12", default-features = false } -tokio-tungstenite = { version = "0.21.0" } -tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } +[lib] +path = "lib/lib.rs" [dependencies] -# internal -entities = { path = "entities" } -grpc = { path = "grpc" } -rustlers = { path = "rustlers" } - -# workspace -eyre = { workspace = true, default-features = false, features = [ - "auto-install", -] } -lool = { workspace = true } -tokio = { workspace = true } - -# external +# utils +eyre = { version = "0.6.12", default-features = false } dotenvy = "0.15.7" chrono = "0.4.37" +getset = "0.1.2" + +# async +tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } +async-trait = "0.1.79" + +# grpc & websocket +tokio-tungstenite = { version = "0.21.0" } +tonic = "0.11.0" +prost = "0.12.3" # protocol buffers + +# database +sea-orm = { version = "0.12.15", features = [ + "runtime-tokio-native-tls", + "sqlx-sqlite", + "macros", +] } +sea-orm-migration = { version = "0.12.15", features = [ + "runtime-tokio-native-tls", + "sqlx-sqlite", +] } + +[dependencies.lool] +version = "0.2.0" # crates: disable-check +registry = "lugit" +features = [ + "cli.stylize", + "logger", + "sched.tokio", + "sched.rule-recurrence", + "macros", +] + +[build-dependencies] +tonic-build = "0.11.0" diff --git a/README.md b/README.md index cafb1ba..e0c82dc 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,15 @@ Also, this library is built using the `Rust` programming language... so, ***rust This library defines the core functionality for a `rustler`. It includes the following: -- A `Rustler` trait that defines the core functionality for a `rustler`. -- A `RustlersSvc` which orchestrates the `rustlers` at runtime, scheduling them to scrape stock pricing data between market hours. +- A [`Rustler`](./lib/rustlers/rustlers.rs) trait that defines the core functionality for a `rustler`. +- A [`RustlersSvc`](./lib/rustlers/svc.rs) which orchestrates the `rustlers` at runtime, scheduling them to scrape stock pricing data between market hours. Apart from the above, this library also defines: -- a database schema for storing market hours, which is used by the `RustlersSvc` to schedule the `rustlers`. -- a grpc service to interact with the rustlers database. +- a [database schema](./lib/entities/orm/) for storing market hours, which is used by the `RustlersSvc` to schedule the `rustlers`. +- initial [database migrations](./lib/entities/migration) to create the schema. +- a [grpc server](./lib/grpc/) to interact with the rustlers database. +- unimplemented a [websocket gateway server](./lib/socket/) to stream stock pricing data to subscribed clients > [!NOTE] > @@ -37,4 +39,8 @@ Apart from the above, this library also defines: > > Although this library contains the core and abstract functionality for the rustlers, it doesn't include any concrete implementation for them. > -> Actual concrete implementations for each market cannot be published for many reasons. \ No newline at end of file +> Actual concrete implementations for each market cannot be published for many reasons. + +## Example + +Check the [examples](./examples) directory for an example of how to use this library. diff --git a/Taskfile.yaml b/Taskfile.yaml index 26987e0..2a9109c 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -16,7 +16,7 @@ tasks: run:watch: desc: 🚀 watch rustler cmds: - - cargo watch -c -x "run" + - cargo watch -c -x "run --example=rustler" build:watch: desc: 🚀 watch rustler «build» diff --git a/check_size.py b/check_size.py deleted file mode 100644 index f88314a..0000000 --- a/check_size.py +++ /dev/null @@ -1,60 +0,0 @@ -""" -small script to run after build, to check if there was a significant -change on executable size, compared to the previous build. - -this aims to detect unwanted big differences before it's too late -""" - - -import os -import pathlib - -curr_dir = pathlib.Path(os.getcwd()) -sizefile_path = pathlib.Path(curr_dir.joinpath('.task')) - - -def bad(txt): - return '\033[91m' + txt + '\033[0m' - - -def good(txt): - return '\033[92m' + txt + '\033[0m' - - -def head(txt): - return '\033[94m' + txt + '\033[0m' - - -files = { - 'release': curr_dir.joinpath('target/release/rustler.exe'), - 'debug': curr_dir.joinpath('target/debug/rustler.exe'), -} - -print("\n🧉 » exe file sizes change\n") - -for key, exe in files.items(): - if exe.is_file(): - sizefile = sizefile_path.joinpath(key) - new_size: float = os.stat(exe).st_size / 1024 - old_size: float - - try: - with open(sizefile, 'r') as f: - old_size = float(f.read()) - except FileNotFoundError: - old_size = 0 - - # diff: str = f'{old_size:.0f}kb' - diff = new_size - old_size - diff_str = f"{'+' if diff > 0 else '=' if diff == 0 else ''}{diff:.0f}kb" - - fmt = bad if diff > 10 else good - - sizefile.parent.mkdir(parents=True, exist_ok=True) - - print( - f'{head(key)}: {fmt(diff_str)} (prev: {old_size}kb, now: {fmt(f"{str(new_size)}kb")})' - ) - - with open(sizefile, 'w') as f: - f.write(f'{new_size}') diff --git a/entities/Cargo.toml b/entities/Cargo.toml deleted file mode 100644 index a3ed977..0000000 --- a/entities/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "entities" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -name = "entities" -path = "src/lib.rs" - -[dependencies] -# common -eyre = { workspace = true, default-features = false } -lool = { workspace = true, features = [ "cli", "cli.stylize", "macros", "logger" ] } - -# external -sea-orm = { version = "0.12.15", features = [ - "runtime-tokio-native-tls", - "sqlx-sqlite", - "macros", -] } diff --git a/rustlers/src/rustlers/binance.rs b/examples/binance/mod.rs similarity index 67% rename from rustlers/src/rustlers/binance.rs rename to examples/binance/mod.rs index a34d249..ede5f57 100644 --- a/rustlers/src/rustlers/binance.rs +++ b/examples/binance/mod.rs @@ -1,33 +1,27 @@ use { - crate::{ + async_trait::async_trait, + eyre::Result, + lool::logger::info, + rustler_core::{ rustler, rustlers::{Rustler, RustlerAccessor, RustlerStatus, Ticker}, }, - async_trait::async_trait, - eyre::Result, - lool::{cli::stylize::Stylize, logger::info}, std::collections::HashMap, }; -const BINANCE_WSS_URL: &str = "wss://stream.binance.com:9443/stream"; -// const MANUAL_CLOSE_CODE: u16 = 4663; -// const MANUAL_CLOSE_REASON: &str = "Manually Disconnected"; - rustler!( - /// 🤠 » **binance rustler** - /// - /// A rustler that steals quotes from Binance - pub struct BinanceRustler {} + /// A fake rustler that does nothing but changing between different statuses. + pub struct FooRustler {} ); -impl BinanceRustler { +impl FooRustler { pub fn create() -> impl Rustler { Self::default() } } #[async_trait] -impl Rustler for BinanceRustler { +impl Rustler for FooRustler { async fn connect(&mut self) -> Result<()> { if self.status == RustlerStatus::Connected || self.status == RustlerStatus::Connecting { return Ok(()); @@ -35,10 +29,7 @@ impl Rustler for BinanceRustler { self.set_status(RustlerStatus::Connecting)?; - info!( - "Connecting to Binance WSS: {}", - BINANCE_WSS_URL.bright_green() - ); + info!("Connecting to data source"); self.set_status(RustlerStatus::Connected)?; @@ -53,7 +44,7 @@ impl Rustler for BinanceRustler { self.set_status(RustlerStatus::Disconnecting)?; - info!("Disconnecting from Binance WSS"); + info!("Disconnecting from data source"); self.set_status(RustlerStatus::Disconnected)?; diff --git a/app/main.rs b/examples/rustler.rs similarity index 58% rename from app/main.rs rename to examples/rustler.rs index d852476..ea40fb0 100644 --- a/app/main.rs +++ b/examples/rustler.rs @@ -1,24 +1,25 @@ +mod binance; + use { + binance::FooRustler, dotenvy::dotenv, - eyre::Result, + eyre::{set_hook, DefaultHandler, Result}, lool::logger::{info, ConsoleLogger, Level}, - rustlers::{rustlerjar, rustlers::binance::BinanceRustler, svc::RustlersSvc}, + rustler_core::{entities::db::get_connection, grpc, rustlerjar, rustlers::svc::RustlersSvc}, tokio::join, }; -// TODO: here we will trigger the start of both the grpc server and the websocket gateway -// look at: https://github.com/hyperium/tonic/discussions/740 - #[tokio::main] async fn main() -> Result<()> { + set_hook(Box::new(DefaultHandler::default_with))?; ConsoleLogger::default_setup(Level::Trace, "rustler")?; dotenv()?; - let conn = entities::db::get_connection().await?; + let conn = get_connection().await?; let mut rustler = RustlersSvc::new( conn.clone(), rustlerjar! { - "BINANCE" => BinanceRustler + "BINANCE" => FooRustler }, ) .await; diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml deleted file mode 100644 index 04e8d20..0000000 --- a/gateway/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "gateway" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -name = "gateway" -path = "src/lib.rs" - -[dependencies] -entities = { path = "../entities" } -eyre = { workspace = true, default-features = false } - diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs deleted file mode 100644 index e69de29..0000000 diff --git a/grpc/Cargo.toml b/grpc/Cargo.toml deleted file mode 100644 index acd802c..0000000 --- a/grpc/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "grpc" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -name = "grpc" -path = "src/lib.rs" - -[dependencies] -# common -lool = { workspace = true, features = ["logger"]} -eyre = { workspace = true, default-features = false } - -# internal -entities = { path = "../entities" } - -# external -prost = "0.12.3" -tonic = "0.11.0" - -[build-dependencies] -tonic-build = "0.11.0" - diff --git a/grpc/build.rs b/lib/build.rs similarity index 71% rename from grpc/build.rs rename to lib/build.rs index 2d85665..1ac75f0 100644 --- a/grpc/build.rs +++ b/lib/build.rs @@ -1,5 +1,9 @@ fn main() { - let proto_files = vec!["./proto/rustler.proto", "./proto/market.proto", "./proto/ticker.proto"]; + let proto_files = vec![ + "./lib/grpc/proto/rustler.proto", + "./lib/grpc/proto/market.proto", + "./lib/grpc/proto/ticker.proto", + ]; for proto_file in proto_files { compile_proto(proto_file); diff --git a/migration/src/m20220101_000001_create_table_market.rs b/lib/entities/migration/m20220101_000001_create_table_market.rs similarity index 98% rename from migration/src/m20220101_000001_create_table_market.rs rename to lib/entities/migration/m20220101_000001_create_table_market.rs index 45c2c2f..3af09fb 100644 --- a/migration/src/m20220101_000001_create_table_market.rs +++ b/lib/entities/migration/m20220101_000001_create_table_market.rs @@ -1,6 +1,7 @@ use sea_orm_migration::{async_trait::async_trait, prelude::*}; #[derive(DeriveMigrationName)] +/// 🤠 » create table `market` pub struct Migration; #[async_trait] diff --git a/migration/src/m20240325_200049_create_table_ticker.rs b/lib/entities/migration/m20240325_200049_create_table_ticker.rs similarity index 97% rename from migration/src/m20240325_200049_create_table_ticker.rs rename to lib/entities/migration/m20240325_200049_create_table_ticker.rs index d006c58..6fea9fa 100644 --- a/migration/src/m20240325_200049_create_table_ticker.rs +++ b/lib/entities/migration/m20240325_200049_create_table_ticker.rs @@ -1,6 +1,7 @@ use sea_orm_migration::{async_trait::async_trait, prelude::*}; #[derive(DeriveMigrationName)] +/// 🤠 » create table `ticker` pub struct Migration; #[async_trait] diff --git a/lib/entities/migration/mod.rs b/lib/entities/migration/mod.rs new file mode 100644 index 0000000..9b9514c --- /dev/null +++ b/lib/entities/migration/mod.rs @@ -0,0 +1,2 @@ +mod m20220101_000001_create_table_market; +mod m20240325_200049_create_table_ticker; diff --git a/entities/src/lib.rs b/lib/entities/mod.rs similarity index 98% rename from entities/src/lib.rs rename to lib/entities/mod.rs index d5ea9ea..7eaf2c5 100644 --- a/entities/src/lib.rs +++ b/lib/entities/mod.rs @@ -1,3 +1,4 @@ +pub mod migration; pub use sea_orm; mod orm { diff --git a/entities/src/orm/market.rs b/lib/entities/orm/market.rs similarity index 96% rename from entities/src/orm/market.rs rename to lib/entities/orm/market.rs index 402f366..a04589d 100644 --- a/entities/src/orm/market.rs +++ b/lib/entities/orm/market.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "market")] +/// 🤠 » market entity model pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/entities/src/orm/ticker.rs b/lib/entities/orm/ticker.rs similarity index 96% rename from entities/src/orm/ticker.rs rename to lib/entities/orm/ticker.rs index 2e3e94c..92fda31 100644 --- a/entities/src/orm/ticker.rs +++ b/lib/entities/orm/ticker.rs @@ -4,6 +4,7 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "ticker")] +/// 🤠 » ticker entity model pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: String, diff --git a/entities/src/services/market.rs b/lib/entities/services/market.rs similarity index 83% rename from entities/src/services/market.rs rename to lib/entities/services/market.rs index 72177b5..00acc94 100644 --- a/entities/src/services/market.rs +++ b/lib/entities/services/market.rs @@ -1,5 +1,5 @@ use { - crate::{ + crate::entities::{ market::{Entity as Market, Model as MarketModel}, ticker::{Entity as Ticker, Model as TickerModel}, }, @@ -7,6 +7,7 @@ use { sea_orm::{DatabaseConnection, DbErr, EntityTrait, IntoActiveModel}, }; +/// 🤠 » service for the `Market` entity pub struct Service { conn: DatabaseConnection, } @@ -16,16 +17,19 @@ impl Service { Self { conn } } + /// 🤠 » gets all markets from the database pub async fn get_all(&self) -> Result, DbErr> { let markets = Market::find().all(&self.conn).await?; Ok(markets) } + /// 🤠 » gets a market by its id pub async fn create(&self, market: MarketModel) -> Result { Market::insert(market.clone().into_active_model()).exec(&self.conn).await?; Ok(market) } + /// 🤠 » gets all markets with their tickers pub async fn get_all_with_tickers( &self, ) -> Result)>, DbErr> { diff --git a/entities/src/services/ticker.rs b/lib/entities/services/ticker.rs similarity index 94% rename from entities/src/services/ticker.rs rename to lib/entities/services/ticker.rs index 77c5494..f0c7ea0 100644 --- a/entities/src/services/ticker.rs +++ b/lib/entities/services/ticker.rs @@ -1,5 +1,5 @@ use { - crate::{ + crate::entities::{ orm::ticker, ticker::{Entity as Ticker, Model as TickerModel}, }, @@ -7,6 +7,7 @@ use { sea_orm::{ColumnTrait, DatabaseConnection, DbErr, EntityTrait, IntoActiveModel, QueryFilter}, }; +/// 🤠 » service for the `Ticker` entity pub struct Service { conn: DatabaseConnection, } diff --git a/grpc/src/lib.rs b/lib/grpc/mod.rs similarity index 81% rename from grpc/src/lib.rs rename to lib/grpc/mod.rs index 6d1d02f..5e7e19f 100644 --- a/grpc/src/lib.rs +++ b/lib/grpc/mod.rs @@ -1,12 +1,15 @@ mod services { use { - entities::sea_orm::{DbErr, SqlErr}, lool::s, + sea_orm::{DbErr, SqlErr}, }; + /// market grpc services pub mod market; + /// ticker grpc services pub mod ticker; + /// general error handling for sql errors in grpc services pub(crate) fn handle_sql_err(err: DbErr, action: &str, entity_name: &str) -> tonic::Status { let sqlerr = err.sql_err(); diff --git a/grpc/proto/market.proto b/lib/grpc/proto/market.proto similarity index 100% rename from grpc/proto/market.proto rename to lib/grpc/proto/market.proto diff --git a/grpc/proto/rustler.proto b/lib/grpc/proto/rustler.proto similarity index 100% rename from grpc/proto/rustler.proto rename to lib/grpc/proto/rustler.proto diff --git a/grpc/proto/ticker.proto b/lib/grpc/proto/ticker.proto similarity index 100% rename from grpc/proto/ticker.proto rename to lib/grpc/proto/ticker.proto diff --git a/grpc/src/server.rs b/lib/grpc/server.rs similarity index 79% rename from grpc/src/server.rs rename to lib/grpc/server.rs index 9cb75c5..e002930 100644 --- a/grpc/src/server.rs +++ b/lib/grpc/server.rs @@ -1,15 +1,18 @@ use { - crate::services, - entities::{market, sea_orm::DatabaseConnection, ticker}, + crate::{ + entities::{market, ticker}, + grpc::services, + }, eyre::Result, lool::{cli::stylize::Stylize, logger::info}, + sea_orm::DatabaseConnection, std::net::SocketAddr, tonic::transport::Server, }; const RUSTLER_GRPC_API_ADDR: &str = "RUSTLER_GRPC_API_ADDR"; -/// Starts the gRPC server +/// 🤠 » starts the rustler gRPC server pub async fn start(conn: DatabaseConnection) -> Result<()> { fn get_default_addr() -> String { let addr = "0.0.0.0:50051"; @@ -36,8 +39,8 @@ pub async fn start(conn: DatabaseConnection) -> Result<()> { ); Server::builder() - .add_service(market_grpc.svc()) - .add_service(ticker_grpc.svc()) + .add_service(market_grpc.svc()) // add the market api + .add_service(ticker_grpc.svc()) // add the ticker api .serve(addr) .await?; diff --git a/grpc/src/services/market.rs b/lib/grpc/services/market.rs similarity index 94% rename from grpc/src/services/market.rs rename to lib/grpc/services/market.rs index 74068ca..39b5362 100644 --- a/grpc/src/services/market.rs +++ b/lib/grpc/services/market.rs @@ -1,7 +1,6 @@ use { self::market_mod::Empty, - crate::services::handle_sql_err, - entities::market, + crate::{entities::market, grpc::services::handle_sql_err}, eyre::Result, lool::logger::{error, info}, market_mod::{ @@ -48,6 +47,7 @@ impl Market { } } +/// 🤠 » grpc Server to manage market entities pub struct GrpcServer { pub(crate) svc: market::Service, } @@ -59,6 +59,7 @@ impl GrpcServer { } } + /// 🤠 » creates the market api server pub fn svc(self) -> MarketApiServer { MarketApiServer::new(self) } diff --git a/grpc/src/services/ticker.rs b/lib/grpc/services/ticker.rs similarity index 94% rename from grpc/src/services/ticker.rs rename to lib/grpc/services/ticker.rs index cca1fb4..b32e6fc 100644 --- a/grpc/src/services/ticker.rs +++ b/lib/grpc/services/ticker.rs @@ -1,6 +1,5 @@ use { - crate::services::handle_sql_err, - entities::ticker, + crate::{entities::ticker, grpc::services::handle_sql_err}, eyre::Result, lool::logger::{error, info}, std::{any::Any, fmt::Debug, time::Instant}, @@ -33,6 +32,7 @@ impl Ticker { } } +/// 🤠 » grpc Server to manage ticker entities pub struct GrpcServer { pub(crate) svc: ticker::Service, } @@ -44,6 +44,7 @@ impl GrpcServer { } } + /// 🤠 » creates the ticker api server pub fn svc(self) -> TickerApiServer { TickerApiServer::new(self) } diff --git a/lib/lib.rs b/lib/lib.rs new file mode 100644 index 0000000..e64b7ba --- /dev/null +++ b/lib/lib.rs @@ -0,0 +1,4 @@ +pub mod entities; +pub mod grpc; +pub mod rustlers; +pub mod socket; diff --git a/lib/rustlers/mod.rs b/lib/rustlers/mod.rs new file mode 100644 index 0000000..8e5f582 --- /dev/null +++ b/lib/rustlers/mod.rs @@ -0,0 +1,6 @@ +mod rustler; + +pub mod rustlerjar; +pub mod svc; + +pub use rustler::*; diff --git a/rustlers/src/rustlers.rs b/lib/rustlers/rustler.rs similarity index 91% rename from rustlers/src/rustlers.rs rename to lib/rustlers/rustler.rs index 44b0dce..aad90c3 100644 --- a/rustlers/src/rustlers.rs +++ b/lib/rustlers/rustler.rs @@ -1,11 +1,10 @@ -pub mod binance; pub extern crate chrono; pub extern crate eyre; use { + crate::entities::{market, ticker}, async_trait::async_trait, chrono::{DateTime, Local}, - entities::{market, ticker}, eyre::Result, std::collections::HashMap, }; @@ -59,6 +58,13 @@ pub struct ScrapperCallbacks { pub on_message: Option Result<()>>, } +/// 🤠 » a scruct representing a ticker +/// +/// in `rustler` a ticker is the union between a symbol (stock identifier) and its market +/// +/// they `key` of a ticker is the concatenation of the market and the symbol separated by a colon +/// +/// e.g. `AAPL` in the `NASDAQ` market would have the key `NASDAQ:AAPL` #[derive(Debug, PartialEq, Eq, Clone)] pub struct Ticker { pub symbol: String, @@ -77,6 +83,7 @@ impl Ticker { tickers.iter().map(|t| Self::from(t, market)).collect() } + /// 🤠 » returns the key of the ticker pub fn key(&self) -> String { format!("{}:{}", self.market, self.symbol) } @@ -123,17 +130,17 @@ pub trait RustlerAccessor { #[async_trait] pub trait Rustler: RustlerAccessor + Send + Sync { // #region Unimplemented trait functions - /// fn called after tickers are added to the rustler + /// 🤠 » fn called after tickers are added to the rustler fn on_add(&mut self, tickers: &[Ticker]) -> Result<()>; - /// fn called after tickers are deleted from the rustler + /// 🤠 » fn called after tickers are deleted from the rustler fn on_delete(&mut self, tickers: &[Ticker]) -> Result<()>; - /// connects the rustler to the data source + /// 🤠 » connects the rustler to the data source async fn connect(&mut self) -> Result<()>; - /// disconnects the rustler from the data source + /// 🤠 » disconnects the rustler from the data source async fn disconnect(&mut self) -> Result<()>; // #endregion - /// should be called at construction time + /// 🤠 » starts the rustler async fn start(&mut self) -> Result<()> { let opts = self.opts(); if opts.connect_on_start { @@ -142,7 +149,7 @@ pub trait Rustler: RustlerAccessor + Send + Sync { Ok(()) } - /// updates last stop and last run times and calls the appropriate callback + /// 🤠 » updates last stop and last run times and calls the appropriate callback /// /// should be called after the status of the rustler changes fn handle_status_change(&mut self) -> Result<()> { @@ -333,7 +340,11 @@ macro_rules! rustler_accessors { }; } -// Define the macro +/// **🤠 » rustler builder macro** +/// +/// The `rustler!` macro is used to define a new `Rustler` struct, expanding the struct definition +/// with the required fields and derives, and implementing the `RustlerAccessor` trait for the +/// struct. #[macro_export] macro_rules! rustler { // Entry point for the macro, takes the struct definition diff --git a/rustlers/src/rustlerjar.rs b/lib/rustlers/rustlerjar.rs similarity index 95% rename from rustlers/src/rustlerjar.rs rename to lib/rustlers/rustlerjar.rs index 3283c52..cad59ba 100644 --- a/rustlers/src/rustlerjar.rs +++ b/lib/rustlers/rustlerjar.rs @@ -1,6 +1,6 @@ use { - crate::rustlers::Rustler, - entities::market, + super::rustler::Rustler, + crate::entities::market, std::{collections::HashMap, sync::Arc}, tokio::sync::Mutex, }; @@ -34,7 +34,7 @@ macro_rules! rustlerjar { instances.push(instance); )* - $crate::rustlerjar::RustlerJar::new(instances, mappings) + $crate::rustlers::rustlerjar::RustlerJar::new(instances, mappings) }}; } diff --git a/rustlers/src/svc.rs b/lib/rustlers/svc.rs similarity index 91% rename from rustlers/src/svc.rs rename to lib/rustlers/svc.rs index 8b9b7cd..26e2cc8 100644 --- a/rustlers/src/svc.rs +++ b/lib/rustlers/svc.rs @@ -1,5 +1,9 @@ use { - entities::{market, sea_orm::DatabaseConnection, ticker}, + super::{ + rustler::{Rustler, Ticker}, + rustlerjar::RustlerJar, + }, + crate::entities::{market, sea_orm::DatabaseConnection, ticker}, eyre::Result, lool::{ logger::{info, warn}, @@ -12,11 +16,6 @@ use { tokio::sync::Mutex, }; -use crate::{ - rustlerjar::RustlerJar, - rustlers::{Rustler, Ticker}, -}; - // interface MarketExecData { // entity: MarketModel; // startJob?: Job; @@ -34,6 +33,9 @@ use crate::{ // stopJob?: Job, // } +/// **🤠 » Rustlers Service** +/// +/// The `RustlersSvc` is a service that manages the rustlers and orchestrates their executions. pub struct RustlersSvc { market_svc: market::Service, sched: Scheduler, @@ -41,7 +43,16 @@ pub struct RustlersSvc { } impl RustlersSvc { + /// **🤠 » create service** + /// /// creates a new instance of the `RustlersSvc` + /// + /// **Arguments** + /// - `conn` - the database connection that will be used to get market and tickers data + /// - `rustlers` - the rustlers to be used by the service + /// + /// **Returns** + /// the created `RustlersSvc` instance pub async fn new(conn: DatabaseConnection, rustlers: RustlerJar) -> Self { let market_svc = market::Service::new(conn).await; let sched = Scheduler::new(); @@ -53,6 +64,8 @@ impl RustlersSvc { } } + /// **🤠 » start rustlers** + /// /// gets market data from the the database and starts /// the corresponding rustler for each market pub async fn start(&mut self) -> Result<()> { @@ -66,6 +79,8 @@ impl RustlersSvc { Ok(()) } + /// **🤠 » restart rustlers** + /// /// stops all rustlers and then starts them again pub async fn restart(&self) -> Result<()> { // TODO: restart all rustlers; this method should clear everything we set up about the @@ -222,6 +237,9 @@ impl RustlersSvc { } } +/// creates a rule for the given time and offset +/// +/// TODO: handle timezones fn make_rule( base: &RecurrenceRuleSet, time: (u32, u32, u32), @@ -239,6 +257,7 @@ fn make_rule( rule } +/// the operation to be performed on the time (addition or subtraction) enum Op { Add, Sub, diff --git a/lib/socket/mod.rs b/lib/socket/mod.rs new file mode 100644 index 0000000..78decec --- /dev/null +++ b/lib/socket/mod.rs @@ -0,0 +1 @@ +// TODO: websocket gateway diff --git a/migration/Cargo.toml b/migration/Cargo.toml deleted file mode 100644 index e914b96..0000000 --- a/migration/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "migration" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -name = "migration" -path = "src/lib.rs" - -[dependencies] -async-std = { version = "1", features = ["attributes", "tokio1"] } -entities = { path = "../entities" } - -[dependencies.sea-orm-migration] -version = "0.12.15" -features = [ - "runtime-tokio-native-tls", - "sqlx-sqlite", -] diff --git a/migration/README.md b/migration/README.md deleted file mode 100644 index 3b438d8..0000000 --- a/migration/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Running Migrator CLI - -- Generate a new migration file - ```sh - cargo run -- generate MIGRATION_NAME - ``` -- Apply all pending migrations - ```sh - cargo run - ``` - ```sh - cargo run -- up - ``` -- Apply first 10 pending migrations - ```sh - cargo run -- up -n 10 - ``` -- Rollback last applied migrations - ```sh - cargo run -- down - ``` -- Rollback last 10 applied migrations - ```sh - cargo run -- down -n 10 - ``` -- Drop all tables from the database, then reapply all migrations - ```sh - cargo run -- fresh - ``` -- Rollback all applied migrations, then reapply all migrations - ```sh - cargo run -- refresh - ``` -- Rollback all applied migrations - ```sh - cargo run -- reset - ``` -- Check the status of all migrations - ```sh - cargo run -- status - ``` diff --git a/migration/src/lib.rs b/migration/src/lib.rs deleted file mode 100644 index f5abbc6..0000000 --- a/migration/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -use sea_orm_migration::async_trait::async_trait; -pub use sea_orm_migration::prelude::*; - -mod m20220101_000001_create_table_market; -mod m20240325_200049_create_table_ticker; - -pub struct Migrator; - -#[async_trait] -impl MigratorTrait for Migrator { - fn migrations() -> Vec> { - vec![ - Box::new(m20220101_000001_create_table_market::Migration), - Box::new(m20240325_200049_create_table_ticker::Migration), - ] - } - - fn migration_table_name() -> sea_orm::DynIden { - Alias::new("migrations").into_iden() - } -} diff --git a/migration/src/main.rs b/migration/src/main.rs deleted file mode 100644 index c6b6e48..0000000 --- a/migration/src/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -use sea_orm_migration::prelude::*; - -#[async_std::main] -async fn main() { - cli::run_cli(migration::Migrator).await; -} diff --git a/rustlers/Cargo.toml b/rustlers/Cargo.toml deleted file mode 100644 index da76124..0000000 --- a/rustlers/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "rustlers" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -name = "rustlers" -path = "src/lib.rs" - -[dependencies] -# workspace -eyre = { workspace = true, default-features = false } -tokio-tungstenite = { workspace = true } -tokio = { workspace = true } -lool = { workspace = true, features = [ - "logger", - "sched.tokio", - "sched.rule-recurrence", - "macros", -] } - -# internal -entities = { path = "../entities" } - -# external -chrono = "0.4.37" -async-trait = "0.1.79" -getset = "0.1.2" - -[build-dependencies] -tonic-build = "0.11.0" diff --git a/rustlers/src/lib.rs b/rustlers/src/lib.rs deleted file mode 100644 index cc08e09..0000000 --- a/rustlers/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod rustlerjar; -pub mod rustlers; -pub mod svc;