From 51ab26fa67429d397330f2fcdc1cb1cce6a119bc Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 02:11:20 +0800 Subject: [PATCH 1/9] feat(WIP): etcd driver structure & signatures changing --- .github/workflows/rust.yml | 12 +- .idea/distributed-scheduler.iml | 1 + Cargo.lock | 726 +++++++++++++- Cargo.toml | 11 +- example/.gitignore | 1 - example/Cargo.lock | 1157 ---------------------- example/Cargo.toml | 14 - examples/etcd.rs | 24 + example/src/main.rs => examples/redis.rs | 6 +- examples/redis_zset.rs | 24 + src/cron.rs | 8 +- src/driver/etcd.rs | 178 ++++ src/driver/mod.rs | 11 +- src/driver/redis.rs | 15 +- src/driver/redis_zset.rs | 2 +- src/driver/utils.rs | 6 +- src/node_pool.rs | 40 +- 17 files changed, 1014 insertions(+), 1222 deletions(-) delete mode 100644 example/.gitignore delete mode 100644 example/Cargo.lock delete mode 100644 example/Cargo.toml create mode 100644 examples/etcd.rs rename example/src/main.rs => examples/redis.rs (76%) create mode 100644 examples/redis_zset.rs create mode 100644 src/driver/etcd.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..495d6e6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,8 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v4 + + - name: Build + run: cargo build --verbose --futures full + + - name: Run tests + run: cargo test --verbose --futures full diff --git a/.idea/distributed-scheduler.iml b/.idea/distributed-scheduler.iml index b72b1fa..8ab7950 100644 --- a/.idea/distributed-scheduler.iml +++ b/.idea/distributed-scheduler.iml @@ -4,6 +4,7 @@ + diff --git a/Cargo.lock b/Cargo.lock index 97a986b..843306b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -32,6 +41,34 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "async-trait" version = "0.1.80" @@ -49,6 +86,51 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.73" @@ -64,12 +146,24 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.5.0" @@ -172,16 +266,53 @@ version = "1.1.0" dependencies = [ "async-trait", "chrono", + "etcd-client", "hashring", "job_scheduler", "log", "md5", + "pretty_env_logger", "redis", "thiserror", "tokio", "uuid 1.9.1", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "error-chain" version = "0.10.0" @@ -191,6 +322,40 @@ dependencies = [ "backtrace", ] +[[package]] +name = "etcd-client" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b915bb9b1e143ab7062e0067ed663e3dfeffc69ce0ceb9e93b35fecfc158d28" +dependencies = [ + "http", + "prost", + "tokio", + "tokio-stream", + "tonic", + "tonic-build", + "tower", + "tower-service", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -200,6 +365,15 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + [[package]] name = "futures-core" version = "0.3.30" @@ -248,6 +422,37 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap 2.2.6", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "hashring" version = "0.3.5" @@ -257,12 +462,94 @@ dependencies = [ "siphasher", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -416,6 +703,46 @@ dependencies = [ "utf8_iter", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", +] + +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -448,6 +775,12 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "litemap" version = "0.7.3" @@ -460,6 +793,12 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "md5" version = "0.7.0" @@ -472,6 +811,12 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.7.3" @@ -492,6 +837,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "multimap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" + [[package]] name = "nom" version = "4.1.1" @@ -547,6 +898,36 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap 2.2.6", +] + +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -559,6 +940,32 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "pretty_env_logger" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" +dependencies = [ + "env_logger", + "log", +] + +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.85" @@ -568,6 +975,59 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" +dependencies = [ + "bytes", + "heck", + "itertools", + "log", + "multimap", + "once_cell", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn", + "tempfile", +] + +[[package]] +name = "prost-derive" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" +dependencies = [ + "prost", +] + [[package]] name = "quote" version = "1.0.36" @@ -577,6 +1037,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redis" version = "0.25.4" @@ -603,6 +1093,35 @@ dependencies = [ "url", ] +[[package]] +name = "regex" +version = "1.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "ring" version = "0.17.8" @@ -624,6 +1143,19 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" version = "0.22.4" @@ -657,7 +1189,7 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" dependencies = [ - "base64", + "base64 0.22.1", "rustls-pki-types", ] @@ -678,6 +1210,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + [[package]] name = "ryu" version = "1.0.18" @@ -699,7 +1237,7 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -748,6 +1286,15 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -793,6 +1340,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "synstructure" version = "0.13.1" @@ -804,6 +1357,27 @@ dependencies = [ "syn", ] +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.61" @@ -851,6 +1425,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-macros" version = "2.3.0" @@ -873,6 +1457,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.11" @@ -886,6 +1481,115 @@ dependencies = [ "tokio", ] +[[package]] +name = "tonic" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.21.7", + "bytes", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-build" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4ef6dd70a610078cb4e338a0f79d06bc759ff1b22d2120c2ff02ae264ba9c2" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "quote", + "syn", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "indexmap 1.9.3", + "pin-project", + "pin-project-lite", + "rand", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "unicode-ident" version = "1.0.12" @@ -939,6 +1643,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -999,6 +1712,15 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "windows-core" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index de6c2e1..716a1d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,10 @@ readme = "README.md" license = "AGPL-3.0-or-later" [features] -default = ["redis_driver"] +full = ["driver-redis", "driver-etcd"] -redis_driver = ["dep:redis"] +driver-redis = ["dep:redis"] +driver-etcd = ["dep:etcd-client"] [dependencies] thiserror = "1.0" @@ -22,6 +23,10 @@ log = "0.4" md5 = "0.7.0" hashring = "0.3.5" uuid = { version = "1.9.1", features = ["v4"] } +chrono = "0.4" redis = { version = "0.25", optional = true, features = ["tokio-rustls-comp"] } -chrono = "0.4" +etcd-client = { version = "0.13", optional = true } + +[dev-dependencies] +pretty_env_logger = "0.5" diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index ea8c4bf..0000000 --- a/example/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/example/Cargo.lock b/example/Cargo.lock deleted file mode 100644 index 9a378f3..0000000 --- a/example/Cargo.lock +++ /dev/null @@ -1,1157 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "async-trait" -version = "0.1.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "autocfg" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - -[[package]] -name = "cc" -version = "1.0.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c891175c3fb232128f48de6590095e59198bbeb8620c310be349bfc3afd12c7b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-targets 0.52.5", -] - -[[package]] -name = "combine" -version = "4.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" -dependencies = [ - "bytes", - "futures-core", - "memchr", - "pin-project-lite", - "tokio", - "tokio-util", -] - -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" - -[[package]] -name = "cron" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab00a636277f7ea5d8dd92ac7a5099fc9a46e5327bba84d3640b41ae127eada9" -dependencies = [ - "chrono", - "error-chain", - "nom", -] - -[[package]] -name = "distributed-scheduler" -version = "1.1.0" -dependencies = [ - "async-trait", - "chrono", - "hashring", - "job_scheduler", - "log", - "md5", - "redis", - "thiserror", - "tokio", - "uuid 1.9.1", -] - -[[package]] -name = "distributed-scheduler-example" -version = "0.1.0" -dependencies = [ - "chrono", - "distributed-scheduler", - "job_scheduler", - "log", - "pretty_env_logger", - "redis", - "tokio", - "uuid 1.9.1", -] - -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - -[[package]] -name = "error-chain" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" -dependencies = [ - "backtrace", -] - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-core", - "futures-sink", - "futures-task", - "pin-project-lite", - "pin-utils", -] - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - -[[package]] -name = "hashring" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2e670d8fa425ec0d91dae7d6ab4a32721e775060a5d2d7cd572a9f0736dfddc" -dependencies = [ - "siphasher", -] - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "iana-time-zone" -version = "0.1.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "job_scheduler" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51f368c9c76dde2282714ae32dc274b79c27527a0c06c816f6dda048904d0d7c" -dependencies = [ - "chrono", - "cron", - "uuid 0.8.2", -] - -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "libc" -version = "0.2.155" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" - -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "md5" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "nom" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c349f68f25f596b9f44cf0e7c69752a5c633b0550c3ff849518bfba0233774a" -dependencies = [ - "memchr", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.52.5", -] - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pretty_env_logger" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" -dependencies = [ - "env_logger", - "log", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redis" -version = "0.25.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0d7a6955c7511f60f3ba9e86c6d02b3c3f144f8c24b288d1f4e18074ab8bbec" -dependencies = [ - "async-trait", - "bytes", - "combine", - "futures-util", - "itoa", - "percent-encoding", - "pin-project-lite", - "rustls", - "rustls-native-certs", - "rustls-pemfile", - "rustls-pki-types", - "ryu", - "sha1_smol", - "socket2", - "tokio", - "tokio-rustls", - "tokio-util", - "url", -] - -[[package]] -name = "redox_syscall" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" -dependencies = [ - "bitflags", -] - -[[package]] -name = "regex" -version = "1.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" - -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "spin", - "untrusted", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "rustls" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-native-certs" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" -dependencies = [ - "openssl-probe", - "rustls-pemfile", - "rustls-pki-types", - "schannel", - "security-framework", -] - -[[package]] -name = "rustls-pemfile" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" -dependencies = [ - "base64", - "rustls-pki-types", -] - -[[package]] -name = "rustls-pki-types" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" - -[[package]] -name = "rustls-webpki" -version = "0.102.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - -[[package]] -name = "signal-hook-registry" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" -dependencies = [ - "libc", -] - -[[package]] -name = "siphasher" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "thiserror" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tinyvec" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-rustls" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" -dependencies = [ - "rustls", - "rustls-pki-types", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "url" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom", -] - -[[package]] -name = "uuid" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" -dependencies = [ - "getrandom", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "winapi-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "windows-core" -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", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -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_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", -] - -[[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_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -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" - -[[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_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -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" - -[[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_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[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_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -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" - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/example/Cargo.toml b/example/Cargo.toml deleted file mode 100644 index cb48cef..0000000 --- a/example/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "distributed-scheduler-example" -version = "0.1.0" -edition = "2021" - -[dependencies] -distributed-scheduler = { path = ".." } -redis = { version = "0.25", features = ["tokio-rustls-comp"] } -tokio = { version = "1", features = ["full"] } -job_scheduler = "1.2.1" -log = "0.4" -pretty_env_logger = "0.5" -uuid = "1.9" -chrono = "0.4" diff --git a/examples/etcd.rs b/examples/etcd.rs new file mode 100644 index 0000000..1ef0877 --- /dev/null +++ b/examples/etcd.rs @@ -0,0 +1,24 @@ +use std::error::Error; + +use distributed_scheduler::{cron, driver, node_pool}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + pretty_env_logger::init(); + + let etcd = etcd_client::Client::connect(vec!["localhost:2379"], None).await?; + + let driver = driver::etcd::EtcdDriver::new(etcd, "example-service", &uuid::Uuid::new_v4().to_string()).await?; + let np = node_pool::NodePool::new(driver).await?; + let cron = cron::Cron::new(np).await; + + log::info!("Adding job"); + cron.add_job("test", "* * * * * *".parse().unwrap(), || { + log::info!("Running job: {}", chrono::Utc::now()); + }).await?; + + log::info!("Starting cron"); + cron.start().await; + + Ok(()) +} diff --git a/example/src/main.rs b/examples/redis.rs similarity index 76% rename from example/src/main.rs rename to examples/redis.rs index 24b85c5..e40d3b7 100644 --- a/example/src/main.rs +++ b/examples/redis.rs @@ -8,9 +8,9 @@ async fn main() -> Result<(), Box> { let rdb = redis::Client::open("redis://localhost:6379").unwrap(); - let driver = driver::redis::RedisDriver::new(rdb, "example-service", &uuid::Uuid::new_v4().to_string()).await?; - let np = node_pool::NodePool::new(driver); - let cron = cron::Cron::new(np).await?; + let driver = driver::redis::RedisDriver::new(rdb, "example-service", &uuid::Uuid::new_v4().to_string()).await?.with_timeout(3); + let np = node_pool::NodePool::new(driver).await?; + let cron = cron::Cron::new(np).await; log::info!("Adding job"); cron.add_job("test", "* * * * * *".parse().unwrap(), || { diff --git a/examples/redis_zset.rs b/examples/redis_zset.rs new file mode 100644 index 0000000..f10cb92 --- /dev/null +++ b/examples/redis_zset.rs @@ -0,0 +1,24 @@ +use std::error::Error; + +use distributed_scheduler::{cron, driver, node_pool}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + pretty_env_logger::init(); + + let rdb = redis::Client::open("redis://localhost:6379").unwrap(); + + let driver = driver::redis_zset::RedisZSetDriver::new(rdb, "example-service", &uuid::Uuid::new_v4().to_string()).await?; + let np = node_pool::NodePool::new(driver).await?; + let cron = cron::Cron::new(np).await; + + log::info!("Adding job"); + cron.add_job("test", "* * * * * *".parse().unwrap(), || { + log::info!("Running job: {}", chrono::Utc::now()); + }).await?; + + log::info!("Starting cron"); + cron.start().await; + + Ok(()) +} diff --git a/src/cron.rs b/src/cron.rs index b6bc899..1ed46ca 100644 --- a/src/cron.rs +++ b/src/cron.rs @@ -29,14 +29,12 @@ async fn run_cron<'a>(job_scheduler: Arc> impl<'a> Cron<'a> { /// Create a new cron with the given node pool. - pub async fn new(mut np: node_pool::NodePool) -> Result { - np.init().await?; - - Ok(Self { + pub async fn new(np: node_pool::NodePool) -> Self { + Self { node_pool: Arc::new(np), jobs: Mutex::new(HashMap::new()), cron: Arc::new(RwLock::new(job_scheduler::JobScheduler::new())), - }) + } } /// Start the cron, blocking the current thread. diff --git a/src/driver/etcd.rs b/src/driver/etcd.rs new file mode 100644 index 0000000..6b18710 --- /dev/null +++ b/src/driver/etcd.rs @@ -0,0 +1,178 @@ +use std::collections::HashSet; +use std::sync::Arc; + +use etcd_client::*; +use tokio::sync::{Mutex, RwLock}; + +use super::{Driver, utils}; + +const ETCD_DEFAULT_LEASE_TTL: i64 = 5; + +pub struct EtcdDriver { + client: Arc>, + + service_name: String, + node_id: String, + + watcher: Option, + lease_keeper: Option, + node_list: Arc>>, +} + +impl std::fmt::Debug for EtcdDriver { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f + .debug_struct("EtcdDriver") + .field("service_name", &self.service_name) + .field("node_id", &self.node_id) + .field("watcher", &self.watcher) + .field("node_list", &self.node_list) + .finish() + } +} + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("Etcd error: {0}")] + Etcd(#[from] etcd_client::Error), + #[error("Empty service name")] + EmptyServiceName, + #[error("Empty node id")] + EmptyNodeId, + #[error("Driver not started")] + DriverNotStarted, +} + +impl EtcdDriver { + /// Create a new etcd driver with the given client, service name, and node id. + pub async fn new(client: Client, service_name: &str, node_id: &str) -> Result { + if service_name.is_empty() { + return Err(Error::EmptyServiceName); + } + + if node_id.is_empty() { + return Err(Error::EmptyNodeId); + } + + Ok(Self { + client: Arc::new(Mutex::new(client)), + service_name: service_name.into(), + node_id: node_id.into(), + watcher: None, + lease_keeper: None, + node_list: Arc::new(RwLock::new(HashSet::new())), + }) + } +} + +#[async_trait::async_trait] +impl Driver for EtcdDriver { + fn node_id(&self) -> String { + self.node_id.clone() + } + + async fn get_nodes(&self) -> Result, Box> { + if self.lease_keeper.is_none() || self.lease_keeper.is_none() { + return Err(Error::DriverNotStarted.into()); + } + + let node_list = self.node_list.read().await; + let nodes = node_list.iter().cloned().collect(); + Ok(nodes) + } + + async fn start(&mut self) -> Result<(), Box> { + let mut client = self.client.lock().await; + + // init node list + let mut node_list = self.node_list.write().await; + for kv in client.get(utils::get_key_prefix(&self.service_name), Some(GetOptions::new().with_prefix())).await?.kvs() { + node_list.insert(kv.value_str()?.into()); + } + + // watch for node changes + { + let (watcher, mut watch_stream) = client.watch(utils::get_key_prefix(&self.service_name), Some(WatchOptions::new().with_prefix())).await?; + self.watcher = Some(watcher); + let node_list = self.node_list.clone(); + tokio::spawn(async move { + log::info!("Watching for changes"); + + loop { + match watch_stream.message().await { + Ok(Some(resp)) => { + for event in resp.events() { + let key = match event.kv() { + Some(kv) if kv.value_str().is_ok() => kv.value_str().unwrap(), + _ => continue, + }; + + match event.event_type() { + EventType::Put => { + node_list.write().await.insert(key.into()); + } + EventType::Delete => { + node_list.write().await.remove(key); + } + } + } + } + Ok(None) => panic!("Watch stream closed"), + Err(e) => panic!("Watch error: {:?}", e), + } + } + }); + } + + // register current node + { + log::info!("Registering node: {}", self.node_id); + + // grant a lease for the node key + let lease = client.lease_grant(ETCD_DEFAULT_LEASE_TTL, None).await?; + log::debug!("Lease granted: {:?}", lease); + + // keep the lease alive + let (keeper, mut ka_stream) = client.lease_keep_alive(lease.id()).await?; + self.lease_keeper = Some(keeper); + + // spawn a task to keep the lease alive + tokio::spawn(async move { + loop { + match ka_stream.message().await { + Ok(Some(_)) => {} + Ok(None) => panic!("Keep alive stream closed"), + Err(e) => panic!("Keep alive error: {:?}", e), + } + } + }); + + // put the node key + let k = utils::get_key_prefix(&self.service_name) + &self.node_id; + let res = client.put(k.as_str(), k.as_str(), Some(PutOptions::new().with_lease(lease.id()))).await?; + log::debug!("Put result: {:?}", res); + } + + Ok(()) + } +} + +impl Drop for EtcdDriver { + fn drop(&mut self) { + if let Some(mut watcher) = self.watcher.take() { + tokio::spawn(async move { + watcher.cancel().await.expect("Failed to cancel watcher"); + }); + } + + if let Some(keeper) = self.lease_keeper.take() { + let client = self.client.clone(); + let key = utils::get_key_prefix(&self.service_name) + &self.node_id; + + tokio::spawn(async move { + client.lock().await.lease_revoke(keeper.id()).await.expect("Failed to revoke lease"); + client.lock().await.delete(key, None).await.expect("Failed to delete node key"); + }); + } + } +} diff --git a/src/driver/mod.rs b/src/driver/mod.rs index da156cd..a802fe6 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -2,16 +2,21 @@ use std::fmt::Debug; mod utils; -#[cfg(feature = "redis_driver")] +#[cfg(feature = "driver-redis")] pub mod redis; -#[cfg(feature = "redis_driver")] +#[cfg(feature = "driver-redis")] pub mod redis_zset; +#[cfg(feature = "driver-etcd")] +pub mod etcd; + #[async_trait::async_trait] pub trait Driver: Send + Sync + Debug { fn node_id(&self) -> String; async fn get_nodes(&self) -> Result, Box>; - async fn start(&self) -> Result<(), Box>; + async fn start(&mut self) -> Result<(), Box> { + Ok(()) + } } diff --git a/src/driver/redis.rs b/src/driver/redis.rs index da7cc9b..6fdaa21 100644 --- a/src/driver/redis.rs +++ b/src/driver/redis.rs @@ -5,6 +5,8 @@ use redis::AsyncCommands; use super::{Driver, utils}; +const DEFAULT_TIMEOUT: u64 = 5; + #[derive(Debug)] pub struct RedisDriver { con: redis::aio::MultiplexedConnection, @@ -40,9 +42,18 @@ impl RedisDriver { service_name: service_name.into(), node_id: utils::get_key_prefix(service_name) + node_id, started: Arc::new(AtomicBool::new(false)), - timeout: 5, + timeout: DEFAULT_TIMEOUT, }) } + + pub fn with_timeout(mut self, timeout: u64) -> Self { + self.timeout = timeout; + self + } + + pub fn timeout(&self) -> u64 { + self.timeout + } } @@ -65,7 +76,7 @@ impl Driver for RedisDriver { Ok(nodes) } - async fn start(&self) -> Result<(), Box> { + async fn start(&mut self) -> Result<(), Box> { // check if the driver has already started if self.started.load(std::sync::atomic::Ordering::SeqCst) { log::warn!("Driver has already started"); diff --git a/src/driver/redis_zset.rs b/src/driver/redis_zset.rs index 3028bf3..3777f18 100644 --- a/src/driver/redis_zset.rs +++ b/src/driver/redis_zset.rs @@ -62,7 +62,7 @@ impl Driver for RedisZSetDriver { Ok(nodes) } - async fn start(&self) -> Result<(), Box> { + async fn start(&mut self) -> Result<(), Box> { // check if the driver has already started if self.started.load(std::sync::atomic::Ordering::SeqCst) { log::warn!("Driver has already started"); diff --git a/src/driver/utils.rs b/src/driver/utils.rs index 1e234b3..b4cc61b 100644 --- a/src/driver/utils.rs +++ b/src/driver/utils.rs @@ -4,8 +4,9 @@ pub fn get_key_prefix(service_name: &str) -> String { format!("{}:{}:", GLOBAL_KEY_PREFIX, service_name) } +#[cfg(feature = "driver-redis")] pub fn get_zset_key(service_name: &str) -> String { - format!("{}:{}:zset", GLOBAL_KEY_PREFIX, service_name) + format!("{}:{}", GLOBAL_KEY_PREFIX, service_name) } #[cfg(test)] @@ -18,7 +19,8 @@ mod tests { } #[test] + #[cfg(feature = "driver-redis")] fn test_get_zset_key() { - assert_eq!(get_zset_key("test"), "distributed-scheduler:test:zset"); + assert_eq!(get_zset_key("test"), "distributed-scheduler:test"); } } diff --git a/src/node_pool.rs b/src/node_pool.rs index 39e0b11..8fa368f 100644 --- a/src/node_pool.rs +++ b/src/node_pool.rs @@ -28,15 +28,24 @@ pub enum Error { impl NodePool { /// Create a new node pool with the given driver. - pub fn new(driver: T) -> Self { - Self { - node_id: String::new(), - pre_nodes: RwLock::new(Vec::new()), - hash: RwLock::new(hashring::HashRing::new()), + pub async fn new(mut driver: T) -> Result { + driver.start().await?; + + // Update the hash ring + let mut pre_nodes = Vec::new(); + let mut hash = hashring::HashRing::new(); + let state_lock = AtomicBool::new(false); + + update_hash_ring(&mut pre_nodes, &state_lock, &mut hash, &driver.get_nodes().await?).await?; + + Ok(Self { + node_id: driver.node_id(), + pre_nodes: RwLock::new(pre_nodes), + hash: RwLock::new(hash), driver: Arc::new(driver), - state_lock: AtomicBool::new(false), + state_lock, stop: AtomicBool::new(false), - } + }) } /// Start the node pool, blocking the current thread. @@ -75,23 +84,6 @@ impl NodePool { } } - /// Initialize the node pool. - pub(crate) async fn init(&mut self) -> Result<(), Error> { - self.driver.start().await?; - self.node_id = self.driver.node_id(); - - // Update the hash ring - let mut pre_nodes = self.pre_nodes.write().await; - let mut hash = self.hash.write().await; - - update_hash_ring(&mut pre_nodes, &self.state_lock, &mut hash, &self.driver.get_nodes().await?).await?; - - drop(pre_nodes); - drop(hash); - - Ok(()) - } - /// Check if the job should be executed on the current node. pub(crate) async fn check_job_available(&self, job_name: &str) -> Result { let hash = self.hash.read().await; From b935c45d80a2d4c5ad4b2f55e29210ef0c0bedd5 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 02:31:31 +0800 Subject: [PATCH 2/9] fix: able to run task in single replicas mode in etcd driver --- src/driver/etcd.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/driver/etcd.rs b/src/driver/etcd.rs index 6b18710..8ffc3a4 100644 --- a/src/driver/etcd.rs +++ b/src/driver/etcd.rs @@ -56,8 +56,8 @@ impl EtcdDriver { Ok(Self { client: Arc::new(Mutex::new(client)), + node_id: utils::get_key_prefix(service_name) + node_id, service_name: service_name.into(), - node_id: node_id.into(), watcher: None, lease_keeper: None, node_list: Arc::new(RwLock::new(HashSet::new())), @@ -96,8 +96,6 @@ impl Driver for EtcdDriver { self.watcher = Some(watcher); let node_list = self.node_list.clone(); tokio::spawn(async move { - log::info!("Watching for changes"); - loop { match watch_stream.message().await { Ok(Some(resp)) => { @@ -108,13 +106,9 @@ impl Driver for EtcdDriver { }; match event.event_type() { - EventType::Put => { - node_list.write().await.insert(key.into()); - } - EventType::Delete => { - node_list.write().await.remove(key); - } - } + EventType::Put => node_list.write().await.insert(key.into()), + EventType::Delete => node_list.write().await.remove(key), + }; } } Ok(None) => panic!("Watch stream closed"), @@ -138,18 +132,23 @@ impl Driver for EtcdDriver { // spawn a task to keep the lease alive tokio::spawn(async move { + log::info!("Starting keep alive"); + loop { match ka_stream.message().await { - Ok(Some(_)) => {} + Ok(Some(r)) => log::debug!("Keep alive response: {:?}", r), Ok(None) => panic!("Keep alive stream closed"), Err(e) => panic!("Keep alive error: {:?}", e), } } }); + if let Some(keeper) = self.lease_keeper.as_mut() { + keeper.keep_alive().await?; + } + // put the node key - let k = utils::get_key_prefix(&self.service_name) + &self.node_id; - let res = client.put(k.as_str(), k.as_str(), Some(PutOptions::new().with_lease(lease.id()))).await?; + let res = client.put(self.node_id.as_str(), self.node_id.as_str(), Some(PutOptions::new().with_lease(lease.id()))).await?; log::debug!("Put result: {:?}", res); } @@ -167,11 +166,8 @@ impl Drop for EtcdDriver { if let Some(keeper) = self.lease_keeper.take() { let client = self.client.clone(); - let key = utils::get_key_prefix(&self.service_name) + &self.node_id; - tokio::spawn(async move { client.lock().await.lease_revoke(keeper.id()).await.expect("Failed to revoke lease"); - client.lock().await.delete(key, None).await.expect("Failed to delete node key"); }); } } From aa9a64ac62eec53d50b166d9921c981b7d8f7978 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 03:05:05 +0800 Subject: [PATCH 3/9] fix: etcd distributed state synchronization --- src/driver/etcd.rs | 76 ++++++++++++++++++++++------------------------ src/node_pool.rs | 1 + 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/driver/etcd.rs b/src/driver/etcd.rs index 8ffc3a4..d825725 100644 --- a/src/driver/etcd.rs +++ b/src/driver/etcd.rs @@ -1,5 +1,6 @@ use std::collections::HashSet; use std::sync::Arc; +use std::sync::atomic::AtomicBool; use etcd_client::*; use tokio::sync::{Mutex, RwLock}; @@ -14,8 +15,7 @@ pub struct EtcdDriver { service_name: String, node_id: String, - watcher: Option, - lease_keeper: Option, + stop: Arc, node_list: Arc>>, } @@ -25,7 +25,7 @@ impl std::fmt::Debug for EtcdDriver { .debug_struct("EtcdDriver") .field("service_name", &self.service_name) .field("node_id", &self.node_id) - .field("watcher", &self.watcher) + .field("stop", &self.stop) .field("node_list", &self.node_list) .finish() } @@ -58,8 +58,7 @@ impl EtcdDriver { client: Arc::new(Mutex::new(client)), node_id: utils::get_key_prefix(service_name) + node_id, service_name: service_name.into(), - watcher: None, - lease_keeper: None, + stop: Arc::new(AtomicBool::new(true)), node_list: Arc::new(RwLock::new(HashSet::new())), }) } @@ -72,42 +71,51 @@ impl Driver for EtcdDriver { } async fn get_nodes(&self) -> Result, Box> { - if self.lease_keeper.is_none() || self.lease_keeper.is_none() { - return Err(Error::DriverNotStarted.into()); + if self.stop.load(std::sync::atomic::Ordering::SeqCst) { + return Err(Box::new(Error::DriverNotStarted)); } - let node_list = self.node_list.read().await; - let nodes = node_list.iter().cloned().collect(); - Ok(nodes) + Ok(self.node_list.read().await.iter().cloned().collect()) } async fn start(&mut self) -> Result<(), Box> { let mut client = self.client.lock().await; + self.stop.store(false, std::sync::atomic::Ordering::SeqCst); // init node list let mut node_list = self.node_list.write().await; for kv in client.get(utils::get_key_prefix(&self.service_name), Some(GetOptions::new().with_prefix())).await?.kvs() { - node_list.insert(kv.value_str()?.into()); + node_list.insert(kv.key_str()?.into()); } // watch for node changes { - let (watcher, mut watch_stream) = client.watch(utils::get_key_prefix(&self.service_name), Some(WatchOptions::new().with_prefix())).await?; - self.watcher = Some(watcher); + let (mut watcher, mut watch_stream) = client.watch(utils::get_key_prefix(&self.service_name), Some(WatchOptions::new().with_prefix())).await?; let node_list = self.node_list.clone(); + let stop = self.stop.clone(); tokio::spawn(async move { loop { + if stop.load(std::sync::atomic::Ordering::SeqCst) { + watcher.cancel().await.expect("Failed to cancel watcher"); + break; + } + match watch_stream.message().await { Ok(Some(resp)) => { + if resp.canceled() { + log::warn!("Watch stream canceled: {:?}", resp); + break; + } + for event in resp.events() { let key = match event.kv() { - Some(kv) if kv.value_str().is_ok() => kv.value_str().unwrap(), + Some(kv) if kv.key_str().is_ok() => kv.key_str().unwrap().to_string(), _ => continue, }; match event.event_type() { - EventType::Put => node_list.write().await.insert(key.into()), - EventType::Delete => node_list.write().await.remove(key), + EventType::Put => node_list.write().await.insert(key), + EventType::Delete => node_list.write().await.remove(&key), }; } } @@ -124,32 +132,33 @@ impl Driver for EtcdDriver { // grant a lease for the node key let lease = client.lease_grant(ETCD_DEFAULT_LEASE_TTL, None).await?; - log::debug!("Lease granted: {:?}", lease); + let lease_id = lease.id(); // keep the lease alive - let (keeper, mut ka_stream) = client.lease_keep_alive(lease.id()).await?; - self.lease_keeper = Some(keeper); + let (mut keeper, mut ka_stream) = client.lease_keep_alive(lease.id()).await?; + let stop = self.stop.clone(); + let inner_client = self.client.clone(); // spawn a task to keep the lease alive tokio::spawn(async move { - log::info!("Starting keep alive"); + keeper.keep_alive().await.expect("Failed to keep alive"); loop { + if stop.load(std::sync::atomic::Ordering::SeqCst) { + inner_client.lock().await.lease_revoke(lease_id).await.expect("Failed to revoke lease"); + break; + } + match ka_stream.message().await { - Ok(Some(r)) => log::debug!("Keep alive response: {:?}", r), + Ok(Some(_)) => keeper.keep_alive().await.expect("Failed to keep alive"), Ok(None) => panic!("Keep alive stream closed"), Err(e) => panic!("Keep alive error: {:?}", e), } } }); - if let Some(keeper) = self.lease_keeper.as_mut() { - keeper.keep_alive().await?; - } - // put the node key - let res = client.put(self.node_id.as_str(), self.node_id.as_str(), Some(PutOptions::new().with_lease(lease.id()))).await?; - log::debug!("Put result: {:?}", res); + client.put(self.node_id.as_str(), self.node_id.as_str(), Some(PutOptions::new().with_lease(lease_id))).await?; } Ok(()) @@ -158,17 +167,6 @@ impl Driver for EtcdDriver { impl Drop for EtcdDriver { fn drop(&mut self) { - if let Some(mut watcher) = self.watcher.take() { - tokio::spawn(async move { - watcher.cancel().await.expect("Failed to cancel watcher"); - }); - } - - if let Some(keeper) = self.lease_keeper.take() { - let client = self.client.clone(); - tokio::spawn(async move { - client.lock().await.lease_revoke(keeper.id()).await.expect("Failed to revoke lease"); - }); - } + self.stop.store(true, std::sync::atomic::Ordering::SeqCst); } } diff --git a/src/node_pool.rs b/src/node_pool.rs index 8fa368f..c92b4a2 100644 --- a/src/node_pool.rs +++ b/src/node_pool.rs @@ -113,6 +113,7 @@ async fn update_hash_ring( nodes: &Vec, ) -> Result<(), Error> { if equal_ring(nodes, pre_nodes) { + log::trace!("Nodes are equal, skipping update, nodes: {:?}", nodes); return Ok(()); } From 2ebd83ccbca67af7b517c6b42dad3baf8e8a37f6 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 03:06:02 +0800 Subject: [PATCH 4/9] doc: etcd driver finished --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a117754..fe90c33 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ The scheduler is composed of a number of components that work together to schedu ## Available Drivers -- [x] Redis (default) +- [x] Redis (Key Scan) - [x] Redis (Z-SET) -- [ ] Etcd +- [x] Etcd (Lease) ## Usage From 09cb76359e481382d1fb13a9063fb169fcd3e57f Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 03:08:27 +0800 Subject: [PATCH 5/9] chore: reduce ttl to 3 seconds, support customizing etcd driver's lease ttl --- src/driver/etcd.rs | 13 +++++++++++-- src/driver/redis.rs | 2 +- src/driver/redis_zset.rs | 9 ++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/driver/etcd.rs b/src/driver/etcd.rs index d825725..d47a331 100644 --- a/src/driver/etcd.rs +++ b/src/driver/etcd.rs @@ -7,7 +7,7 @@ use tokio::sync::{Mutex, RwLock}; use super::{Driver, utils}; -const ETCD_DEFAULT_LEASE_TTL: i64 = 5; +const DEFAULT_LEASE_TTL: i64 = 3; pub struct EtcdDriver { client: Arc>, @@ -17,6 +17,8 @@ pub struct EtcdDriver { stop: Arc, node_list: Arc>>, + + lease_ttl: i64, } impl std::fmt::Debug for EtcdDriver { @@ -60,8 +62,15 @@ impl EtcdDriver { service_name: service_name.into(), stop: Arc::new(AtomicBool::new(true)), node_list: Arc::new(RwLock::new(HashSet::new())), + lease_ttl: DEFAULT_LEASE_TTL, }) } + + /// Set the timeout for the driver. + pub fn with_timeout(mut self, timeout: i64) -> Self { + self.lease_ttl = timeout; + self + } } #[async_trait::async_trait] @@ -131,7 +140,7 @@ impl Driver for EtcdDriver { log::info!("Registering node: {}", self.node_id); // grant a lease for the node key - let lease = client.lease_grant(ETCD_DEFAULT_LEASE_TTL, None).await?; + let lease = client.lease_grant(self.lease_ttl, None).await?; let lease_id = lease.id(); // keep the lease alive diff --git a/src/driver/redis.rs b/src/driver/redis.rs index 6fdaa21..417ada6 100644 --- a/src/driver/redis.rs +++ b/src/driver/redis.rs @@ -5,7 +5,7 @@ use redis::AsyncCommands; use super::{Driver, utils}; -const DEFAULT_TIMEOUT: u64 = 5; +const DEFAULT_TIMEOUT: u64 = 3; #[derive(Debug)] pub struct RedisDriver { diff --git a/src/driver/redis_zset.rs b/src/driver/redis_zset.rs index 3777f18..32d3b9e 100644 --- a/src/driver/redis_zset.rs +++ b/src/driver/redis_zset.rs @@ -6,6 +6,8 @@ use redis::AsyncCommands; use super::{Driver, utils}; +const DEFAULT_TIMEOUT: u64 = 3; + #[derive(Debug)] pub struct RedisZSetDriver { con: redis::aio::MultiplexedConnection, @@ -41,9 +43,14 @@ impl RedisZSetDriver { service_name: service_name.into(), node_id: utils::get_key_prefix(service_name) + node_id, started: Arc::new(AtomicBool::new(false)), - timeout: 5, + timeout: DEFAULT_TIMEOUT, }) } + + pub fn with_timeout(mut self, timeout: u64) -> Self { + self.timeout = timeout; + self + } } From 75f30d663b804b6da376f10aa51c61520bb56c27 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 03:25:02 +0800 Subject: [PATCH 6/9] doc: Cargo.toml optimized --- Cargo.lock | 165 +-------------------------------------- Cargo.toml | 32 ++++++-- src/driver/etcd.rs | 1 + src/driver/redis.rs | 2 +- src/driver/redis_zset.rs | 2 +- 5 files changed, 30 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 843306b..4f5f9a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,12 +152,6 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - [[package]] name = "bitflags" version = "1.3.2" @@ -222,16 +216,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -886,12 +870,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - [[package]] name = "percent-encoding" version = "2.3.1" @@ -1080,15 +1058,10 @@ dependencies = [ "itoa", "percent-encoding", "pin-project-lite", - "rustls", - "rustls-native-certs", - "rustls-pemfile", - "rustls-pki-types", "ryu", "sha1_smol", "socket2", "tokio", - "tokio-rustls", "tokio-util", "url", ] @@ -1122,21 +1095,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "spin", - "untrusted", - "windows-sys 0.52.0", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1156,60 +1114,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustls" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-native-certs" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" -dependencies = [ - "openssl-probe", - "rustls-pemfile", - "rustls-pki-types", - "schannel", - "security-framework", -] - -[[package]] -name = "rustls-pemfile" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" -dependencies = [ - "base64 0.22.1", - "rustls-pki-types", -] - -[[package]] -name = "rustls-pki-types" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" - -[[package]] -name = "rustls-webpki" -version = "0.102.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - [[package]] name = "rustversion" version = "1.0.17" @@ -1222,38 +1126,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "security-framework" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" -dependencies = [ - "bitflags 2.5.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "serde" version = "1.0.203" @@ -1311,24 +1183,12 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "stable_deref_trait" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.66" @@ -1446,17 +1306,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-rustls" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" -dependencies = [ - "rustls", - "rustls-pki-types", - "tokio", -] - [[package]] name = "tokio-stream" version = "0.1.15" @@ -1490,7 +1339,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64 0.21.7", + "base64", "bytes", "h2", "http", @@ -1596,12 +1445,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - [[package]] name = "url" version = "2.5.1" @@ -1926,12 +1769,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" - [[package]] name = "zerovec" version = "0.10.2" diff --git a/Cargo.toml b/Cargo.toml index 716a1d2..f10edda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ description = "A distributed cronjob library" version = "1.1.0" edition = "2021" repository = "https://github.com/AH-dark/distributed-scheduler.git" +homepage = "https://github.com/AH-dark/distributed-scheduler" authors = ["AH-dark "] readme = "README.md" license = "AGPL-3.0-or-later" @@ -14,19 +15,38 @@ full = ["driver-redis", "driver-etcd"] driver-redis = ["dep:redis"] driver-etcd = ["dep:etcd-client"] +[lib] +name = "distributed_scheduler" +path = "src/lib.rs" + +[[example]] +name = "redis" +path = "examples/redis.rs" +required-features = ["driver-redis"] + +[[example]] +name = "redis_zset" +path = "examples/redis_zset.rs" +required-features = ["driver-redis"] + +[[example]] +name = "etcd" +path = "examples/etcd.rs" +required-features = ["driver-etcd"] + [dependencies] +async-trait = "0.1" +chrono = "0.4" thiserror = "1.0" +hashring = "0.3.5" job_scheduler = "1.2.1" -tokio = { version = "1.38", features = ["macros", "rt-multi-thread", "time", "sync"] } -async-trait = "0.1" log = "0.4" md5 = "0.7.0" -hashring = "0.3.5" -uuid = { version = "1.9.1", features = ["v4"] } -chrono = "0.4" +tokio = { version = "1", features = ["macros", "rt-multi-thread", "time", "sync"] } +uuid = { version = "1", features = ["v4"] } -redis = { version = "0.25", optional = true, features = ["tokio-rustls-comp"] } etcd-client = { version = "0.13", optional = true } +redis = { version = "0.25", optional = true, features = ["aio"] } [dev-dependencies] pretty_env_logger = "0.5" diff --git a/src/driver/etcd.rs b/src/driver/etcd.rs index d47a331..9b91fbb 100644 --- a/src/driver/etcd.rs +++ b/src/driver/etcd.rs @@ -9,6 +9,7 @@ use super::{Driver, utils}; const DEFAULT_LEASE_TTL: i64 = 3; +#[derive(Clone)] pub struct EtcdDriver { client: Arc>, diff --git a/src/driver/redis.rs b/src/driver/redis.rs index 417ada6..6f188a8 100644 --- a/src/driver/redis.rs +++ b/src/driver/redis.rs @@ -7,7 +7,7 @@ use super::{Driver, utils}; const DEFAULT_TIMEOUT: u64 = 3; -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct RedisDriver { con: redis::aio::MultiplexedConnection, diff --git a/src/driver/redis_zset.rs b/src/driver/redis_zset.rs index 32d3b9e..aace3fb 100644 --- a/src/driver/redis_zset.rs +++ b/src/driver/redis_zset.rs @@ -8,7 +8,7 @@ use super::{Driver, utils}; const DEFAULT_TIMEOUT: u64 = 3; -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct RedisZSetDriver { con: redis::aio::MultiplexedConnection, From ea801388bd3d1ab6d67bab82239f9573c7cc3d2e Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 03:25:41 +0800 Subject: [PATCH 7/9] ci: typo error --- .github/workflows/rust.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 495d6e6..061dcdf 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,9 +16,9 @@ jobs: steps: - uses: actions/checkout@v4 - + - name: Build - run: cargo build --verbose --futures full + run: cargo build --verbose --features full - name: Run tests - run: cargo test --verbose --futures full + run: cargo test --verbose --features full From 1409200535a3608c8aac8b0ca6fbc590cd8c3f97 Mon Sep 17 00:00:00 2001 From: AHdark Date: Sat, 6 Jul 2024 03:30:04 +0800 Subject: [PATCH 8/9] CI: Added protoc installation --- .github/workflows/rust.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 061dcdf..63d85fe 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,6 +17,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Protoc + uses: arduino/setup-protoc@v3 + - name: Build run: cargo build --verbose --features full From 16d6d8b2d455da3e2b2bcfc7caa678d41cc94fc2 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Sat, 6 Jul 2024 03:38:48 +0800 Subject: [PATCH 9/9] fix: redis features error --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f10edda..63fc642 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread", "time", "sync" uuid = { version = "1", features = ["v4"] } etcd-client = { version = "0.13", optional = true } -redis = { version = "0.25", optional = true, features = ["aio"] } +redis = { version = "0.25", optional = true, features = ["tokio-comp"] } [dev-dependencies] pretty_env_logger = "0.5"