From 85d64f6f3c5f81e30980c0ce35ee3f9556356908 Mon Sep 17 00:00:00 2001 From: Sebastian Rollen Date: Thu, 17 Jun 2021 23:11:41 -0400 Subject: [PATCH] remove webserver --- Cargo.lock | 578 +----------------------------- Cargo.toml | 6 +- src/lib.rs | 1 - src/main.rs | 56 +-- src/relay.rs | 31 +- src/server/mod.rs | 26 -- src/server/routes/health_check.rs | 5 - src/server/routes/mod.rs | 7 - src/server/routes/subscribe.rs | 25 -- src/server/routes/unsubscribe.rs | 27 -- 10 files changed, 29 insertions(+), 733 deletions(-) delete mode 100644 src/server/mod.rs delete mode 100644 src/server/routes/health_check.rs delete mode 100644 src/server/routes/mod.rs delete mode 100644 src/server/routes/subscribe.rs delete mode 100644 src/server/routes/unsubscribe.rs diff --git a/Cargo.lock b/Cargo.lock index 07b63d0..3e46973 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,204 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "actix-codec" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d5dbeb2d9e51344cb83ca7cc170f1217f9fe25bfc50160e6e200b5c31c1019a" -dependencies = [ - "bitflags", - "bytes 1.0.1", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.2.6", - "tokio 1.5.0", - "tokio-util 0.6.6", -] - -[[package]] -name = "actix-http" -version = "3.0.0-beta.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb9c5d7ceb490d6565156ae1d4d467db17da1759425c65a2e36ac5e182e014e2" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "actix-tls", - "actix-utils", - "ahash", - "base64", - "bitflags", - "brotli2", - "bytes 1.0.1", - "bytestring", - "cookie", - "derive_more", - "encoding_rs", - "flate2", - "futures-core", - "futures-util", - "h2 0.3.2", - "http", - "httparse", - "itoa", - "language-tags", - "local-channel", - "log", - "mime", - "once_cell", - "percent-encoding", - "pin-project", - "pin-project-lite 0.2.6", - "rand 0.8.3", - "regex", - "serde 1.0.125", - "serde_json", - "serde_urlencoded", - "sha-1", - "smallvec", - "time 0.2.26", - "tokio 1.5.0", -] - -[[package]] -name = "actix-macros" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbcb2b608f0accc2f5bcf3dd872194ce13d94ee45b571487035864cf966b04ef" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "actix-router" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ad299af73649e1fc893e333ccf86f377751eb95ff875d095131574c6f43452c" -dependencies = [ - "bytestring", - "http", - "log", - "regex", - "serde 1.0.125", -] - -[[package]] -name = "actix-rt" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0" -dependencies = [ - "actix-macros", - "futures-core", - "tokio 1.5.0", -] - -[[package]] -name = "actix-server" -version = "2.0.0-beta.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0872f02a1871257ef09c5a269dce5dc5fea5ccf502adbf5d39f118913b61411c" -dependencies = [ - "actix-rt", - "actix-service", - "actix-utils", - "futures-core", - "log", - "mio 0.7.11", - "num_cpus", - "slab", - "tokio 1.5.0", -] - -[[package]] -name = "actix-service" -version = "2.0.0-beta.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf82340ad9f4e4caf43737fd3bbc999778a268015cdc54675f60af6240bd2b05" -dependencies = [ - "futures-core", - "pin-project-lite 0.2.6", -] - -[[package]] -name = "actix-tls" -version = "3.0.0-beta.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65b7bb60840962ef0332f7ea01a57d73a24d2cb663708511ff800250bbfef569" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "actix-utils", - "derive_more", - "futures-core", - "http", - "log", - "tokio-util 0.6.6", -] - -[[package]] -name = "actix-utils" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e491cbaac2e7fc788dfff99ff48ef317e23b3cf63dbaf7aaab6418f40f92aa94" -dependencies = [ - "local-waker", - "pin-project-lite 0.2.6", -] - -[[package]] -name = "actix-web" -version = "4.0.0-beta.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6de19cc341c2e68b1ee126de171e86b610b5bbcecc660d1250ebed73e0257bd6" -dependencies = [ - "actix-codec", - "actix-http", - "actix-macros", - "actix-router", - "actix-rt", - "actix-server", - "actix-service", - "actix-utils", - "actix-web-codegen", - "ahash", - "bytes 1.0.1", - "derive_more", - "either", - "encoding_rs", - "futures-core", - "futures-util", - "language-tags", - "log", - "mime", - "once_cell", - "pin-project", - "regex", - "serde 1.0.125", - "serde_json", - "serde_urlencoded", - "smallvec", - "socket2 0.4.0", - "time 0.2.26", - "url", -] - -[[package]] -name = "actix-web-codegen" -version = "0.5.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f138ac357a674c3b480ddb7bbd894b13c1b6e8927d728bc9ea5e17eee2f8fc9" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "addr2line" version = "0.14.1" @@ -215,17 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f200cbb1e856866d9eade941cf3aa0c5d7dd36f74311c4273b494f4ef036957" -dependencies = [ - "getrandom 0.2.2", - "once_cell", - "version_check", -] - [[package]] name = "aho-corasick" version = "0.7.15" @@ -276,12 +67,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base-x" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" - [[package]] name = "base64" version = "0.13.0" @@ -312,26 +97,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "brotli-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "brotli2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cb036c3eade309815c15ddbacec5b22c4d1f3983a774ab2eac2e3e9ea85568e" -dependencies = [ - "brotli-sys", - "libc", -] - [[package]] name = "bumpalo" version = "3.6.1" @@ -356,15 +121,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" -[[package]] -name = "bytestring" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90706ba19e97b90786e19dc0d5e2abd80008d99d4c0c5d1ad0b5e72cec7c494d" -dependencies = [ - "bytes 1.0.1", -] - [[package]] name = "cc" version = "1.0.67" @@ -393,7 +149,7 @@ dependencies = [ "num-integer", "num-traits 0.2.14", "serde 1.0.125", - "time 0.1.43", + "time", "winapi 0.3.9", ] @@ -413,29 +169,6 @@ dependencies = [ "yaml-rust", ] -[[package]] -name = "const_fn" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402da840495de3f976eaefc3485b7f5eb5b0bf9761f9a47be27fe975b3b8c2ec" - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "cookie" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" -dependencies = [ - "percent-encoding", - "time 0.2.26", - "version_check", -] - [[package]] name = "core-foundation" version = "0.9.1" @@ -458,15 +191,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" -[[package]] -name = "crc32fast" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "debugid" version = "0.7.2" @@ -488,18 +212,6 @@ dependencies = [ "syn", ] -[[package]] -name = "derive_more" -version = "0.99.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b1b72f1263f214c0f823371768776c4f5841b942c9883aa8e5ec584fd0ba6" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "digest" version = "0.9.0" @@ -509,12 +221,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "dotenv" version = "0.15.0" @@ -536,18 +242,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "flate2" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" -dependencies = [ - "cfg-if 1.0.0", - "crc32fast", - "libc", - "miniz_oxide", -] - [[package]] name = "fnv" version = "1.0.7" @@ -697,16 +391,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "gethostname" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e692e296bfac1d2533ef168d0b60ff5897b8b70a4009276834014dd8924cc028" -dependencies = [ - "libc", - "winapi 0.3.9", -] - [[package]] name = "getrandom" version = "0.1.16" @@ -750,30 +434,11 @@ dependencies = [ "indexmap", "slab", "tokio 0.2.25", - "tokio-util 0.3.1", + "tokio-util", "tracing", "tracing-futures", ] -[[package]] -name = "h2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" -dependencies = [ - "bytes 1.0.1", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio 1.5.0", - "tokio-util 0.6.6", - "tracing", -] - [[package]] name = "hashbrown" version = "0.9.1" @@ -843,14 +508,14 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.2.7", + "h2", "http", "http-body", "httparse", "httpdate", "itoa", "pin-project", - "socket2 0.3.19", + "socket2", "tokio 0.2.25", "tower-service", "tracing", @@ -914,15 +579,6 @@ dependencies = [ "bytes 1.0.1", ] -[[package]] -name = "instant" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "iovec" version = "0.1.4" @@ -981,12 +637,6 @@ dependencies = [ "winapi-build", ] -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" - [[package]] name = "lazy_static" version = "1.4.0" @@ -1030,33 +680,6 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" -[[package]] -name = "local-channel" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6246c68cf195087205a0512559c97e15eaf95198bf0e206d662092cdcb03fe9f" -dependencies = [ - "futures-core", - "futures-sink", - "futures-util", - "local-waker", -] - -[[package]] -name = "local-waker" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f9a2d3e27ce99ce2c3aad0b09b1a7b916293ea9b2bf624c13fe646fadd8da4" - -[[package]] -name = "lock_api" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.14" @@ -1342,31 +965,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "parking_lot" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" -dependencies = [ - "cfg-if 1.0.0", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi 0.3.9", -] - [[package]] name = "percent-encoding" version = "2.1.0" @@ -1437,10 +1035,8 @@ dependencies = [ [[package]] name = "polygon-data-relay" -version = "1.2.6" +version = "1.3.0" dependencies = [ - "actix-service", - "actix-web", "anyhow", "config", "dotenv", @@ -1454,8 +1050,6 @@ dependencies = [ "serde_json", "tokio 1.5.0", "tracing", - "tracing-bunyan-formatter", - "tracing-log", "tracing-subscriber", ] @@ -1753,12 +1347,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "security-framework" version = "2.2.0" @@ -1973,12 +1561,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "sha1" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" - [[package]] name = "sharded-slab" version = "0.1.1" @@ -1988,15 +1570,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "signal-hook-registry" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" -dependencies = [ - "libc", -] - [[package]] name = "sized-chunks" version = "0.6.5" @@ -2030,80 +1603,12 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "socket2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" -dependencies = [ - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde 1.0.125", - "serde_derive", - "syn", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde 1.0.125", - "serde_derive", - "serde_json", - "sha1", - "syn", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "syn" version = "1.0.69" @@ -2168,44 +1673,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "time" -version = "0.2.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros", - "version_check", - "winapi 0.3.9", -] - -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] - -[[package]] -name = "time-macros-impl" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn", -] - [[package]] name = "tinyvec" version = "1.2.0" @@ -2251,12 +1718,8 @@ dependencies = [ "memchr", "mio 0.7.11", "num_cpus", - "once_cell", - "parking_lot", "pin-project-lite 0.2.6", - "signal-hook-registry", "tokio-macros", - "winapi 0.3.9", ] [[package]] @@ -2319,20 +1782,6 @@ dependencies = [ "tokio 0.2.25", ] -[[package]] -name = "tokio-util" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" -dependencies = [ - "bytes 1.0.1", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.2.6", - "tokio 1.5.0", -] - [[package]] name = "toml" version = "0.5.8" @@ -2372,23 +1821,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tracing-bunyan-formatter" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce1eae70720bd6bb3944f7cf501761aeae658bd1f9293aa373c71a195064910" -dependencies = [ - "chrono", - "gethostname", - "log", - "serde 1.0.125", - "serde_json", - "tracing", - "tracing-core", - "tracing-log", - "tracing-subscriber", -] - [[package]] name = "tracing-core" version = "0.1.17" diff --git a/Cargo.toml b/Cargo.toml index a70acb0..c948c63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,12 @@ [package] name = "polygon-data-relay" -version = "1.2.6" +version = "1.3.0" authors = ["Sebastian Rollen "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = "4.0.0-beta.4" -actix-service = "= 2.0.0-beta.5" anyhow = "1.0" config = "0.11.0" dotenv = "0.15" @@ -22,6 +20,4 @@ serde = "1.0" serde_json = "1.0" tokio = {version = "1.2", features = ["macros", "rt-multi-thread"]} tracing = "0.1" -tracing-log = "0.1" tracing-subscriber = "0.2" -tracing-bunyan-formatter = { version = "0.2.4", default-features = false } diff --git a/src/lib.rs b/src/lib.rs index f508b75..87ab487 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,2 @@ pub mod relay; -pub mod server; pub mod settings; diff --git a/src/main.rs b/src/main.rs index d1f889c..37dede6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,23 +2,19 @@ use anyhow::Result; use dotenv::dotenv; use polygon::ws::Connection; use polygon_data_relay::relay::run; -use polygon_data_relay::server::launch_server; use polygon_data_relay::settings::Settings; use sentry_anyhow::capture_anyhow; -use std::sync::mpsc::channel; -use std::thread; use tracing::{debug, info, subscriber::set_global_default}; -use tracing_log::LogTracer; use tracing_subscriber::EnvFilter; -fn main() -> Result<()> { +#[tokio::main] +async fn main() -> Result<()> { let _ = dotenv(); let subscriber = tracing_subscriber::fmt() .json() .with_env_filter(EnvFilter::from_default_env()) .finish(); set_global_default(subscriber).expect("Failed to set subscriber"); - LogTracer::init().expect("Failed to set logger"); let settings = Settings::new()?; let _guard = sentry::init(( settings.sentry.address, @@ -48,42 +44,24 @@ fn main() -> Result<()> { debug!(subscription = "MinuteAggregates", "Subscribing"); } - let (tx, rx) = channel(); - let kafka_settings = settings.kafka; - let server_settings = settings.server; let polygon_settings = settings.polygon; - thread::spawn(move || { - let half_owned: Vec<_> = polygon_settings - .tickers - .iter() - .map(|x| x.as_ref()) - .collect(); - let connection = Connection::new( - &polygon_settings.base_url, - &polygon_settings.key_id, - &data, - &half_owned, - ); - let tokio_runtime = tokio::runtime::Runtime::new().unwrap(); - tokio_runtime.block_on(async { - let res = run(&kafka_settings, connection, rx).await; - if let Err(e) = res { - capture_anyhow(&e); - } - }); - }); - let sys = actix_web::rt::System::new(); - sys.block_on(async move { - let res = launch_server(&server_settings, tx) - .unwrap() - .await - .map_err(From::from); - if let Err(e) = res { - capture_anyhow(&e); - } - }); + let half_owned: Vec<_> = polygon_settings + .tickers + .iter() + .map(|x| x.as_ref()) + .collect(); + let connection = Connection::new( + &polygon_settings.base_url, + &polygon_settings.key_id, + &data, + &half_owned, + ); + let res = run(&kafka_settings, connection).await; + if let Err(e) = res { + capture_anyhow(&e); + } Ok(()) } diff --git a/src/relay.rs b/src/relay.rs index 5b7ab84..ee2bb30 100644 --- a/src/relay.rs +++ b/src/relay.rs @@ -1,34 +1,15 @@ -use anyhow::{anyhow, Context, Result}; -use futures::{SinkExt, StreamExt}; +use anyhow::{Context, Result}; +use futures::StreamExt; use kafka_settings::{producer, KafkaSettings}; -use polygon::ws::{ - Aggregate, Connection, PolygonAction, PolygonMessage, PolygonStatus, Quote, Trade, -}; +use polygon::ws::{Aggregate, Connection, PolygonMessage, PolygonStatus, Quote, Trade}; use rdkafka::producer::FutureRecord; -use std::sync::mpsc::Receiver; use std::time::Duration; -use tracing::{debug, error, info}; +use tracing::{debug, error}; -pub async fn run( - settings: &KafkaSettings, - connection: Connection<'_>, - rx: Receiver, -) -> Result<()> { +pub async fn run(settings: &KafkaSettings, connection: Connection<'_>) -> Result<()> { let producer = producer(settings)?; let ws = connection.connect().await.context("Failed to connect")?; - let (mut sink, stream) = ws.split::(); - tokio::spawn(async move { - loop { - let msg = rx.recv().expect("Failed to receive message"); - let msg_str = serde_json::to_string(&msg).expect("Failed to serialize command"); - info!(%msg_str); - sink.send(msg_str) - .await - .map_err(|_| anyhow!("Failed to send message to Sink")) - .unwrap(); - } - }); - + let (_, stream) = ws.split::(); stream .for_each_concurrent( 10_000, // Equal to 1/10 the max buffer size in rdkafka diff --git a/src/server/mod.rs b/src/server/mod.rs deleted file mode 100644 index e775112..0000000 --- a/src/server/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -use crate::settings::WebServerSettings; -use actix_web::dev::Server; -use actix_web::{web, App, HttpServer}; -use polygon::ws::types::PolygonAction; -use routes::{health_check, subscribe, unsubscribe}; -use std::net::TcpListener; -use std::sync::mpsc::Sender; - -mod routes; - -pub fn launch_server( - settings: &WebServerSettings, - tx: Sender, -) -> Result { - let address = TcpListener::bind(format!("{}:{}", settings.address, settings.port))?; - let server = HttpServer::new(move || { - App::new() - .data(tx.clone()) - .route("/health_check", web::get().to(health_check)) - .route("/subscribe", web::get().to(subscribe)) - .route("/unsubscribe", web::get().to(unsubscribe)) - }) - .listen(address)? - .run(); - Ok(server) -} diff --git a/src/server/routes/health_check.rs b/src/server/routes/health_check.rs deleted file mode 100644 index d7eb4e0..0000000 --- a/src/server/routes/health_check.rs +++ /dev/null @@ -1,5 +0,0 @@ -use actix_web::HttpResponse; - -pub async fn health_check() -> HttpResponse { - HttpResponse::Ok().finish() -} diff --git a/src/server/routes/mod.rs b/src/server/routes/mod.rs deleted file mode 100644 index a70b5f3..0000000 --- a/src/server/routes/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod health_check; -mod subscribe; -mod unsubscribe; - -pub use health_check::*; -pub use subscribe::*; -pub use unsubscribe::*; diff --git a/src/server/routes/subscribe.rs b/src/server/routes/subscribe.rs deleted file mode 100644 index b490775..0000000 --- a/src/server/routes/subscribe.rs +++ /dev/null @@ -1,25 +0,0 @@ -use actix_web::{ - web::{Data, Query}, - HttpResponse, -}; -use polygon::ws::types::PolygonAction; -use serde::Deserialize; -use std::sync::mpsc::Sender; - -#[derive(Deserialize)] -pub struct Subscribe { - stream: String, - ticker: String, -} - -pub async fn subscribe(message: Query, tx: Data>) -> HttpResponse { - let response = tx.send(PolygonAction { - action: "subscribe".into(), - params: format!("{}.{}", message.stream, message.ticker).into(), - }); - - match response { - Ok(_) => HttpResponse::Ok().finish(), - Err(_) => HttpResponse::InternalServerError().finish(), - } -} diff --git a/src/server/routes/unsubscribe.rs b/src/server/routes/unsubscribe.rs deleted file mode 100644 index 0aeffcf..0000000 --- a/src/server/routes/unsubscribe.rs +++ /dev/null @@ -1,27 +0,0 @@ -use actix_web::{ - web::{Data, Query}, - HttpResponse, -}; -use polygon::ws::types::PolygonAction; -use serde::Deserialize; -use std::sync::mpsc::Sender; - -#[derive(Deserialize)] -pub struct Unsubscribe { - stream: String, - ticker: String, -} - -pub async fn unsubscribe( - message: Query, - tx: Data>, -) -> HttpResponse { - let response = tx.send(PolygonAction { - action: "unsubscribe".into(), - params: format!("{}.{}", message.stream, message.ticker).into(), - }); - match response { - Ok(_) => HttpResponse::Ok().finish(), - Err(_) => HttpResponse::InternalServerError().finish(), - } -}