From 69682523ee922f216a89e90aefa3194df7c6da86 Mon Sep 17 00:00:00 2001 From: Sven65 Date: Sat, 30 Sep 2023 16:11:29 +0200 Subject: [PATCH] Fix bug with db connection failing when getting tags --- Cargo.lock | 239 +++++++++++++++++++--------- Cargo.toml | 6 +- Dockerfile | 14 +- Makefile | 2 +- src/commands/commands/tag.rs | 2 +- src/lib.rs | 4 +- src/services/rethinkdb/rethinkdb.rs | 50 ++++-- src/services/rethinkdb/tags.rs | 42 +++-- 8 files changed, 245 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63d0422..9dd65fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,9 +73,9 @@ dependencies = [ [[package]] name = "async-net" -version = "1.6.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5373304df79b9b4395068fb080369ec7178608827306ce4d081cba51cac551df" +checksum = "0434b1ed18ce1cf5769b8ac540e33f01fa9471058b5e89da9e06f3c882a8c12f" dependencies = [ "async-io", "blocking", @@ -84,23 +84,24 @@ dependencies = [ [[package]] name = "async-stream" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" dependencies = [ "async-stream-impl", "futures-core", + "pin-project-lite", ] [[package]] name = "async-stream-impl" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.37", ] [[package]] @@ -117,7 +118,7 @@ checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.99", ] [[package]] @@ -318,7 +319,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 1.0.99", ] [[package]] @@ -329,18 +330,19 @@ checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5" dependencies = [ "darling_core", "quote", - "syn", + "syn 1.0.99", ] [[package]] name = "dashmap" -version = "5.3.4" +version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3495912c9c1ccf2e18976439f4443f3fee0fd61f424ff99fde6a66b15ecb448f" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown", + "hashbrown 0.14.1", "lock_api", + "once_cell", "parking_lot_core", "serde", ] @@ -436,9 +438,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ "futures-channel", "futures-core", @@ -451,9 +453,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -461,15 +463,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-executor" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ "futures-core", "futures-task", @@ -478,9 +480,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-lite" @@ -499,32 +501,32 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.37", ] [[package]] name = "futures-sink" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-util" -version = "0.3.24" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-channel", "futures-core", @@ -594,6 +596,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" + [[package]] name = "heck" version = "0.3.3" @@ -720,7 +728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -776,9 +784,9 @@ checksum = "04c3b4822ccebfa39c02fc03d1534441b22ead323fa0f48bb7ddd8e6ba076a40" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ "autocfg", "scopeguard", @@ -897,9 +905,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "ordered-float" @@ -934,15 +942,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.3.5", "smallvec", - "windows-sys", + "windows-targets", ] [[package]] @@ -1007,7 +1015,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.99", "version_check", ] @@ -1024,9 +1032,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -1071,7 +1079,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 1.0.99", ] [[package]] @@ -1097,9 +1105,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -1143,6 +1151,15 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.6.0" @@ -1180,9 +1197,9 @@ dependencies = [ [[package]] name = "reql" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b661946f3b32b3ab7c0b3a2a1fd52367b7ca255a38aa4554fb75229a084f9cf" +checksum = "5b246691272eb06ba9a305dde4c7c76fb6e054b88041e82095b41ec11aaaa8ad" dependencies = [ "async-net", "async-stream", @@ -1205,7 +1222,7 @@ checksum = "87c5ae88ff96546522eb56ef38cbbdacaa03258166b7335e503d881c288e9d55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.99", ] [[package]] @@ -1357,9 +1374,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.144" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] @@ -1376,20 +1393,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.144" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.37", ] [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -1506,9 +1523,20 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tagbot" -version = "4.0.2" +version = "4.0.3" dependencies = [ "bitflags", "cat-loggr", @@ -1541,7 +1569,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn", + "syn 1.0.99", ] [[package]] @@ -1553,7 +1581,7 @@ dependencies = [ "cfg-if", "fastrand", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "remove_dir_all", "winapi", ] @@ -1577,7 +1605,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.99", ] [[package]] @@ -1597,7 +1625,7 @@ checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.99", ] [[package]] @@ -1681,7 +1709,7 @@ checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.99", ] [[package]] @@ -1717,9 +1745,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", "log", @@ -1730,20 +1758,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.22" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.37", ] [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" dependencies = [ "once_cell", "valuable", @@ -1963,7 +1991,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.99", "wasm-bindgen-shared", ] @@ -1997,7 +2025,7 @@ checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.99", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2085,43 +2113,100 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index c448b3c..cf574c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tagbot" -version = "4.0.2" +version = "4.0.3" edition = "2021" license = "OPL-3.0" publish = false @@ -9,7 +9,7 @@ publish = false [dependencies] dotenv = "0.15" -reql = "0.11.1" +reql = "0.11.2" tokio = { version = "1.20.1", features = ["macros", "rt-multi-thread"] } tracing = "0.1.36" tracing-subscriber = "0.2.0" @@ -33,4 +33,4 @@ features = [ "builder", "cache", "client", "gateway", "http", "model", "utils", [dev-dependencies] test-case = "2.2.1" -serde_json = "1.0.1" \ No newline at end of file +serde_json = "1.0.1" diff --git a/Dockerfile b/Dockerfile index eacd615..b969ff2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,7 @@ ################# COMPILE TAGBOT ################# -FROM rust:1.63.0 as build - +FROM rust:1.72.1-bullseye as build # Capture deps # COPY Cargo.toml Cargo.lock /app/ @@ -13,10 +12,12 @@ FROM rust:1.63.0 as build RUN cargo new --lib /app/ COPY ./Cargo.toml /app/ +COPY ./Cargo.lock /app/ # We do the same for macros RUN cargo new /app/tagbot-macros COPY tagbot-macros/Cargo.toml /app/tagbot-macros/ +COPY tagbot-macros/Cargo.lock /app/tagbot-macros/ COPY ./src /app/src COPY ./tagbot-macros /app/tagbot-macros @@ -86,7 +87,8 @@ RUN luarocks install kikito/sandbox # # TODO: Add luarocks and sandbox -FROM debian:buster-slim as final +# FROM debian:buster-slim as final +FROM debian:bullseye as final WORKDIR /home @@ -130,9 +132,9 @@ COPY --from=lua_modules /usr/local/share/lua/ /usr/local/share/lua/ ## Copy libm bs lmao -COPY --from=build /lib/x86_64-linux-gnu/libm-2.31.so /lib/x86_64-linux-gnu/ -RUN rm /lib/x86_64-linux-gnu/libm.so.6 -RUN ln -s /lib/x86_64-linux-gnu/libm-2.31.so /lib/x86_64-linux-gnu/libm.so.6 +# COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/ +# RUN rm /lib/x86_64-linux-gnu/libm.so.6 +# RUN ln -s /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6 ## Copy tagbot binary diff --git a/Makefile b/Makefile index 5cf7247..efda5ed 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DOCKER_REGISTRY= +DOCKER_REGISTRY ?= PACKAGE_VERSION := $(shell cargo metadata --no-deps --format-version 1 | jq '.packages[0].version' | tr -d '"') IMAGE_NAME := $(shell cargo metadata --no-deps --format-version 1 | jq '.packages[0].name' | tr -d '"') diff --git a/src/commands/commands/tag.rs b/src/commands/commands/tag.rs index d67e62e..7abdae2 100644 --- a/src/commands/commands/tag.rs +++ b/src/commands/commands/tag.rs @@ -32,7 +32,7 @@ pub async fn tag(interaction: ApplicationCommandInteraction, ctx: Context) -> St let gotten_tag = TagsTable::get_tag(name.clone()).await; if gotten_tag.is_err() { - cat_loggr::log_fatal!("{}: {:?}", "Failed to get tag:", gotten_tag.err()); + cat_loggr::log_fatal!("{}: {:?}", "Failed to get tag (1):", gotten_tag.err()); handle_error!( send_app_interaction_message(ctx, interaction, "That tag doesn't exist", false).await, "Failed to send non-existant tag message" diff --git a/src/lib.rs b/src/lib.rs index 0b7e055..7c8ade4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -mod services; mod commands; -mod util; +mod services; pub mod tags; +mod util; diff --git a/src/services/rethinkdb/rethinkdb.rs b/src/services/rethinkdb/rethinkdb.rs index d79f214..8131658 100644 --- a/src/services/rethinkdb/rethinkdb.rs +++ b/src/services/rethinkdb/rethinkdb.rs @@ -1,17 +1,38 @@ use cat_loggr::{log_fatal, log_info}; use dotenv::dotenv; +use futures::lock::Mutex; use lazy_static::lazy_static; use reql::{cmd::connect::Options, r, Session}; -use std::env; +use std::{env, sync::Arc}; use tokio::runtime::Handle; +#[derive(Clone)] +pub struct RethinkDBOptions { + host: String, + port: u16, + db_name: String, + user: String, + password: String, +} + #[derive(Clone)] pub struct RethinkDB { + pub connection_options: Option, pub session: Option, } impl RethinkDB { - async fn init_connection(&mut self) -> Result<&Session, reql::Error> { + pub fn get_options_as_connect(&self) -> Options { + let rdb_opts = self.connection_options.clone().unwrap(); + Options::new() + .host(rdb_opts.host) + .port(rdb_opts.port) + .db(rdb_opts.db_name) + .user(rdb_opts.user) + .password(rdb_opts.password) + } + + pub fn init_options(&mut self) { dotenv().ok(); let host = env::var("RETHINK_HOST").expect("Expected rethinkdb host to be present in env."); @@ -25,14 +46,11 @@ impl RethinkDB { let password = env::var("RETHINK_PASSWORD") .expect("Expected rethinkdb password to be present in env."); - let options = Options::new() - .host(host) - .port(port) - .db(db_name) - .user(user) - .password(password); + self.connection_options = Some(RethinkDBOptions { host, port, db_name, user, password }); + } - let conn = r.connect(options).await?; + pub async fn init_connection(&mut self) -> Result<&Session, reql::Error> { + let conn = r.connect(self.get_options_as_connect()).await?; self.session = Some(conn); @@ -42,11 +60,19 @@ impl RethinkDB { } pub async fn get_connection(&self) -> Option<&Session> { - self.session.as_ref() + let connection = self.session.as_ref(); + + if connection.is_none() { + println!("Connection to DB lost."); + } + + connection } pub fn new() -> Self { - let mut rdb: RethinkDB = RethinkDB { session: None }; + let mut rdb: RethinkDB = RethinkDB { session: None, connection_options: None }; + + rdb.init_options(); let handle = Handle::current(); @@ -69,5 +95,5 @@ impl RethinkDB { } lazy_static! { - pub static ref RDB: RethinkDB = RethinkDB::new(); + pub static ref RDB: Arc> = Arc::new(Mutex::new(RethinkDB::new())); } diff --git a/src/services/rethinkdb/tags.rs b/src/services/rethinkdb/tags.rs index af19010..1ec2735 100644 --- a/src/services/rethinkdb/tags.rs +++ b/src/services/rethinkdb/tags.rs @@ -2,7 +2,7 @@ use futures::TryStreamExt; use reql::{func, r, types::WriteStatus, Session}; use serde::{Deserialize, Serialize}; -use super::rethinkdb::RDB; +use crate::services::rethinkdb::rethinkdb::RDB; macro_rules! create_error { ($($args:tt)*) => { @@ -72,7 +72,8 @@ impl TagsTable { owner_id: String, tag_type: Option, ) -> Result { - let connection = RDB.get_connection().await; + let rdb = RDB.lock().await; + let connection = rdb.get_connection().await; if connection.is_none() { return create_error!("Failed to create tag: Failed to get DB Connection.".to_string()); @@ -100,7 +101,11 @@ impl TagsTable { /// /// * `tag_name` - The name of the tag to get. Automatically converted to lowercase. pub async fn get_tag(tag_name: String) -> Result { - let connection = RDB.get_connection().await; + let mut rdb_lock = RDB.lock().await; + + let rdb = rdb_lock.to_owned(); + + let connection = rdb.get_connection().await; if connection.is_none() { return create_error!("Failed to get tag: Failed to get DB Connection."); @@ -113,11 +118,19 @@ impl TagsTable { .get(tag_name.to_lowercase()) .run::<&Session, Tag>(connection); - if let Some(result) = query.try_next().await? { - return Ok(result); + match query.try_next().await { + Ok(Some(result)) => Ok(result), + Ok(None) => create_error!("Failed to get tag"), + Err(_) => { + rdb_lock.init_connection().await?; + Ok(Tag { + content: "Failed to get tag, please try again.".to_string(), + id: "failed-tag".to_string(), + owner: "1".to_string(), + tag_type: Some(TagType::Legacy), + }) + } // Propagate the error } - - create_error!("Failed to get tag") } /// Deletes a tag from the tags table, if it exists. @@ -126,7 +139,8 @@ impl TagsTable { /// /// * `tag_name` - The name of the tag to delete. Automatically converted to lowercase. pub async fn delete_tag(tag_name: String) -> Result { - let connection = RDB.get_connection().await; + let rdb = RDB.lock().await; + let connection = rdb.get_connection().await; if connection.is_none() { return create_error!("Failed to get tag: Failed to get DB Connection."); @@ -151,7 +165,8 @@ impl TagsTable { /// Gets all tags in the database pub async fn get_all() -> Result, reql::Error> { - let connection = RDB.get_connection().await; + let rdb = RDB.lock().await; + let connection = rdb.get_connection().await; if connection.is_none() { return create_error!("Failed to get all tags: Failed to get DB Connection."); @@ -176,7 +191,8 @@ impl TagsTable { /// /// * `owner_id` - The id of the user whose tags to get pub async fn get_all_by_owner(owner_id: String) -> Result, reql::Error> { - let connection = RDB.get_connection().await; + let rdb = RDB.lock().await; + let connection = rdb.get_connection().await; if connection.is_none() { return create_error!("Failed to get user tags: Failed to get DB Connection."); @@ -208,7 +224,8 @@ impl TagsTable { tag_name: String, new_owner: String, ) -> Result { - let connection = RDB.get_connection().await; + let rdb = RDB.lock().await; + let connection = rdb.get_connection().await; if connection.is_none() { return create_error!("Failed to set tag owner: Failed to get DB Connection."); @@ -241,7 +258,8 @@ impl TagsTable { tag_name: String, new_content: String, ) -> Result { - let connection = RDB.get_connection().await; + let rdb = RDB.lock().await; + let connection = rdb.get_connection().await; if connection.is_none() { return create_error!("Failed to set tag content: Failed to get DB Connection.");