From 99b8ed32e51f8ba30672bd1521e4c0a9497d0c34 Mon Sep 17 00:00:00 2001 From: prplV Date: Fri, 16 Aug 2024 12:28:57 +0300 Subject: [PATCH] 0_0 global config handling mechanism rebuild 0_0 --- Cargo.lock | 275 ++++++++++++++++-------------------------- Cargo.toml | 2 +- src/main.rs | 341 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 313 insertions(+), 305 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed7a62e..c4393ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,9 +43,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -58,36 +58,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -131,15 +131,18 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.0.104" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" +checksum = "5fb8dd288a69fc53a1996d7ecfbf4a20d59065bff137ce7e56bbd620de191189" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -158,14 +161,14 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-targets", ] [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "combine" @@ -179,15 +182,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "env_filter" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" dependencies = [ "log", "regex", @@ -195,9 +198,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" dependencies = [ "anstream", "anstyle", @@ -296,9 +299,9 @@ dependencies = [ [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" @@ -308,9 +311,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -354,13 +357,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -372,21 +376,11 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" -version = "0.36.1" +version = "0.36.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" +checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" dependencies = [ "memchr", ] @@ -417,7 +411,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.52.5", + "windows-targets", ] [[package]] @@ -467,18 +461,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ "bitflags 2.6.0", ] [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -505,7 +499,7 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "runner-rs" -version = "0.4.9" +version = "0.5.0" dependencies = [ "chrono", "env_logger", @@ -537,18 +531,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.203" +version = "1.0.207" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.207" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" dependencies = [ "proc-macro2", "quote", @@ -557,20 +551,27 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.118" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] [[package]] name = "sha1_smol" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" @@ -594,14 +595,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "syn" -version = "2.0.68" +version = "2.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" dependencies = [ "proc-macro2", "quote", @@ -625,28 +626,27 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.0" +version = "1.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -699,19 +699,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -724,9 +725,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -734,9 +735,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -747,9 +748,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "windows-core" @@ -757,16 +758,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", + "windows-targets", ] [[package]] @@ -775,126 +767,69 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "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 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 80b67c7..b1b7473 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runner-rs" -version = "0.4.9" +version = "0.5.0" edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index 61322e8..87b4a4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use redis::Commands; +use redis::{Client, Commands, Connection}; // json parsing use serde::{ Deserialize, Serialize }; use serde_json; @@ -6,6 +6,7 @@ use serde_json; use tokio::time::{ Duration, Instant }; use tokio::sync::mpsc; use tokio::join; +// use tokio::io::{AsyncRead, AsyncWrite}; // fatal errors handler use core::panic; // utils @@ -18,9 +19,9 @@ use std::sync::Arc; use inotify::{ Inotify, WatchMask }; // logging use std::io::Write; -use chrono::{Local, Utc}; +use chrono::Local; use env_logger::Builder; -use log::{error, warn, LevelFilter}; +use log::{error, info, warn, LevelFilter}; use std::net::{TcpStream, ToSocketAddrs}; static CONFIG_PATH : &'static str = "settings.json"; @@ -29,6 +30,10 @@ static CONFIG_PATH : &'static str = "settings.json"; enum CustomError { Fatal, } +enum ConfigActuality { + Local, + Remote, +} /// # struct for the 1st level in json conf file /// > (needed in serialization and deserialization) @@ -117,124 +122,10 @@ async fn main() { // setting up redis connection \ // then conf checks to choose the most actual \ - let client = redis::Client::open("redis://127.0.0.1").expect("error connecting redis server"); - let mut conn = client.get_connection().expect("error getting connection"); - - log::info!("Waitng for a config file from DB ..."); - if let Ok(len) = conn.xlen::<&str, usize>("config_stream") { - if len <= 0 { - warn!("No configuration in DB yet. Waiting ..."); - while conn.xlen::<&str, usize>("config_stream").unwrap() <= 0 { - std::thread::sleep(Duration::from_millis(400)); - } - } - } else { - error!("Cannot find needed stream to get configuration"); - return; - } - - let conf: redis::RedisResult)>>> = conn.xrevrange_count("config_stream", "+", "-", 1); - let mut config: Vec<(String, Vec<(String, String)>)> = Vec::new(); - if conf.is_ok() { - // guarranted safe unwrapping - config = conf.unwrap()[0].clone(); - // let idx = config[0].0.find('-').unwrap(); - // let true_milis: i64 = config[0].0 - // .chars() - // .enumerate() - // .filter(|(id, _)| *id < idx) - // .map(|(_, chr)| chr) - // .collect::() - // .parse() - // .unwrap(); - // let date = chrono::DateTime::from_timestamp_millis(true_milis).unwrap(); - // log::info!("Log from {} was given", date); - } else { - // rewrite error handler - println!("error: {}", conf.unwrap_err()); - } - - let processes: Processes; - if config.is_empty() { - error!("No suitable configs were given!"); - log::info!("Trying to get local config..."); - // matching check - match load_processes(CONFIG_PATH) { - Some(prcs) => processes = prcs, - None => { - error!("No config for runner. Cannot continue running..."); - return; - }, - } - } else { - // matching check - match parse_extern_config(&config[0].1[0].1) { - Some(prcs) => { - // - // comparing and optionally rewriting config file - // - if let Some(local) = load_processes(CONFIG_PATH) { - // comparing - let local_date: u64 = local.date_of_creation.parse().unwrap(); - let external_date: u64 = prcs.date_of_creation.parse().unwrap(); - match local_date.cmp(&external_date) { - std::cmp::Ordering::Less => { - // server has sent newest version - warn!("Updating config (new version - {})...", &native_date_from_milis(&prcs.date_of_creation).unwrap()); - processes = prcs; - let _ = save_new_config(&processes, CONFIG_PATH); - }, - std::cmp::Ordering::Equal => { - // server has sent equal version - processes = prcs; - log::info!("Local version is actual"); - }, - std::cmp::Ordering::Greater => { - // server has sent an elder version - log::warn!("Local config version is more actual"); - processes = local; - }, - } - } else { - // settings.json can be deleted - processes = prcs; - match std::fs::File::create(CONFIG_PATH) { - Ok(_) => { - // saving server conf (truncating or adding new) - let _ = save_new_config(&processes, CONFIG_PATH); - }, - Err(_) => { - error!("Cannot create or truncate local config file"); - }, - } - - } - }, - None => { - //temp - warn!("External config file parsing failed. Trying to get local config..."); - if let Some(prcs) = load_processes(CONFIG_PATH) { - processes = prcs; - let date_of_creation: Result = processes.date_of_creation.parse(); - if date_of_creation.is_err() { - error!("Local config date of creation parsing failed. Returning..."); - return; - } else { - let date_of_creation = date_of_creation.unwrap(); - if let Some(date) = chrono::DateTime::from_timestamp_millis(date_of_creation) { - log::info!("Config from {} is actual now!", date); - } else { - error!("Local config date of creation parsing failed. Returning..."); - return; - } - } - } else { - error!("No config for runner. Cannot continue running..."); - return; - } - }, - } - } + let processes: Processes = get_actual_config().unwrap_or_else(|| { + error!("No actual configuration for runner"); + std::process::exit(101); + }); log::info!("Current runner configuration: {}\n", &processes.date_of_creation); @@ -269,12 +160,173 @@ async fn main() { return; } -fn native_date_from_milis(mls: &str) -> Option> { - match mls.parse::(){ - Ok(val) => return chrono::DateTime::from_timestamp_millis(val), - Err(_) => return None, +fn get_actual_config() -> Option { + + // todo: local check Some|None -> redis check + // * if no conf -> loop and +inf getting conf from redis server + // let mut local = load_processes(&CONFIG_PATH); + match load_processes(&CONFIG_PATH) { + Some(local_conf) => { + if let Some(remote_conf) = once_get_remote_configuration("redis://localhost") { + match config_comparing(&local_conf, &remote_conf) { + ConfigActuality::Local => { + info!("Local config is actual"); + return Some(local_conf); + }, + ConfigActuality::Remote => { + info!("Pulled config is more actual. Saving changes!"); + if save_new_config(&remote_conf, &CONFIG_PATH).is_err() { + error!("Saving changes process failed due to unexpected error...") + } + return Some(remote_conf); + }, + } + } + return Some(local_conf); + }, + None => { + // ? ? OUTSTANDING CONSTRUCTION ? + let mut conn = get_connection_watcher(&open_watcher("redis://localhost")); + get_stream_info_watcher(&mut conn); + let remote_config = invalid_config_watcher(&mut conn); + let _ = save_new_config(&remote_config, &CONFIG_PATH); + Some(remote_config) + }, } } +// ! once iter exec +// ! only for situation when local isnt None (no need to fck redis server) +fn once_get_remote_configuration(serv_info: &str) -> Option { + match redis::Client::open(serv_info) { + Ok(client) => { + match client.get_connection() { + Ok(mut conn) => { + if let Ok(len) = conn.xlen::<&str, usize>("config_stream") { + if len == 0 { + warn!("No configuration in DB yet"); + return None; + } else { + let conf: redis::RedisResult)>>> = conn.xrevrange_count("config_stream", "+", "-", 1); + let config: &Vec<(String, Vec<(String, String)>)>; + + if conf.is_ok() { + // guarranted safe unwrapping + let conf = conf.unwrap(); + config = &conf[0]; + if config.is_empty() { + error!("Empty config was pulled. Check stream and configs state!"); + return None; + } + match parse_extern_config(&config[0].1[0].1) { + Some(prcs) => return Some(prcs), + None => { + error!("Invalid configuration was pulled (PARSING_ERROR). Check configs state!"); + return None; + }, + } + } else { + error!("Configuration pulling from Redis stream failed. Check stream state!"); + return None; + } + } + } else { + error!("Cannot find config_stream. Check Redis-stream accessibility!"); + return None; + } + }, + Err(_) => { + error!("Redis connection attempt is failed. Check Redis configuration!"); + return None; + }, + } + }, + Err(_) => { + error!("Redis-Client opening attempt is failed. Check network configuration!"); + return None; + }, + } +} + +// ! watchers + +fn open_watcher(serv_info: &str) -> redis::Client { + loop { + match redis::Client::open(serv_info) { + Ok(redis) => { + info!("Succesfully opened Redis-Client"); + return redis + }, + Err(_) => { + error!("Redis-Client opening attempt is failed. Check network configuration! Retrying..."); + std::thread::sleep(Duration::from_secs(4)); + } + } + } +} + +fn get_connection_watcher(client: &Client) -> Connection { + loop { + match client.get_connection() { + Ok(conn) => { + info!("Succesfully got Redis connection object"); + return conn; + }, + Err(_) => { + error!("Redis connection attempt is failed. Check Redis configuration! Retrying..."); + std::thread::sleep(Duration::from_secs(4)); + } + } + } +} +fn get_stream_info_watcher(conn: &mut Connection) { + loop { + if let Ok(val) = conn.xlen::<&str, usize>("config_stream") { + if val != 0 { + info!("Redis stream is able and not empty now"); + return; + } + } + error!("Configuration pulling from Redis stream failed. Check stream state! Retrying..."); + std::thread::sleep(Duration::from_secs(4)); + } +} +fn invalid_config_watcher(conn: &mut Connection) -> Processes { + // let res: redis::RedisResult)>>>; + loop { + let res: redis::RedisResult)>>> = conn.xrevrange_count("config_stream", "+", "-", 1); + if res.is_ok() { + let config = &res.unwrap()[0]; + if !config.is_empty() { + if let Some(conf) = parse_extern_config(&config[0].1[0].1) { + return conf; + } + } + } + error!("Got INVALID configuration. Update config! Retrying..."); + std::thread::sleep(Duration::from_secs(4)); + } +} + +// ! end of watchers + +fn config_comparing(local: &Processes, remote: &Processes) -> ConfigActuality { + let local_date: u64 = local.date_of_creation.parse().unwrap(); + let remote_date: u64 = remote.date_of_creation.parse().unwrap(); + + match local_date.cmp(&remote_date) { + std::cmp::Ordering::Equal | + std::cmp::Ordering::Greater => return ConfigActuality::Local, + std::cmp::Ordering::Less => return ConfigActuality::Remote, + } +} + +// ! TEMPORARLY DEPRICATED ! +// fn native_date_from_milis(mls: &str) -> Option> { +// match mls.parse::(){ +// Ok(val) => return chrono::DateTime::from_timestamp_millis(val), +// Err(_) => return None, +// } +// } fn save_new_config(config: &Processes, config_file: &str) -> Result<(), CustomError> { match serde_json::to_string_pretty(&config) { @@ -290,8 +342,10 @@ fn save_new_config(config: &Processes, config_file: &str) -> Result<(), CustomEr async fn create_watcher(filename: &str, path: &str) -> Result { let src = format!("{}{}", path, filename); - let mut inotify: Inotify = Inotify::init().expect(&("Error: Cannot create watcher for ".to_owned() + &src)); - + let mut inotify = Inotify::init().unwrap_or_else(|_| { + error!("{}",format!("Cannot create watcher for {}", &src)); + std::process::exit(101); + }); _ = inotify .watches() .add( @@ -414,7 +468,6 @@ async fn run_daemons( // 4ever sync fn load_processes(json_filename: &str) -> Option{ - // let read = fs::read_to_string(json_filename);//.expect(format!("Missing '{}' file. Cannot start runner", json_filename).as_str()); match fs::read_to_string(json_filename) { Ok(res) => { match serde_json::from_str::(&res) { @@ -446,18 +499,26 @@ async fn get_pid(name: &str) -> Output { Command::new("pidof") .arg(&*name) .output() - .expect("Failed to execute command 'pidof'") + .unwrap_or_else(|_| { + error!("Failed to execute command 'pidof'"); + std::process::exit(101); + }) }) .await .unwrap() } +// ! can be with bug !!! +// * APPROVED async fn is_active(name: &str)-> bool { let arc_name = Arc::new(name.to_string()); tokio::task::spawn_blocking(move || { let output = Command::new("pidof") .arg(&*arc_name) .output() - .expect("Failed to execute command 'pidof'"); + .unwrap_or_else(|_| { + error!("Failed to execute command 'pidof'"); + std::process::exit(101); + }); !String::from_utf8_lossy(&output.stdout).trim().is_empty() }) .await @@ -475,7 +536,10 @@ async fn is_frozen(name: &str) -> bool { let cmd = Command::new("ps") .args(["-o", "stat=", "-p", &arc_pid]) .output() - .expect("Failed to execute ps command"); + .unwrap_or_else(|_| { + error!("Failed to execute ps command"); + std::process::exit(101); + }); !(String::from_utf8_lossy(&cmd.stdout) == "Sl+\n") }) .await @@ -486,19 +550,28 @@ async fn terminate_process (name: &str) { let _ = Command::new("pkill") .arg(name) .output() - .expect("Failed to execute command 'pkill'"); + .unwrap_or_else(|_| { + error!("Failed to execute command 'pkill'"); + std::process::exit(101); + }); } async fn freeze_process(name: &str) { let _ = Command::new("pkill") .args(["-STOP", name]) .output() - .expect("Failed to freeze process"); + .unwrap_or_else(|_| { + error!("Failed to freeze process"); + std::process::exit(101); + }); } async fn unfreeze_process(name: &str) { let _ = Command::new("pkill") .args(["-CONT", name]) .output() - .expect("Failed to unfreeze process"); + .unwrap_or_else(|_| { + error!("Failed to unfreeze process"); + std::process::exit(101); + }); } async fn restart_process(name: &str, path: &str) -> Result<(), CustomError> { terminate_process(name).await;