Server tools to backfill, tail, mirror, and verify PLC logs

lazy: reqwest retry crate for 429s

+236 -25
+219 -20
Cargo.lock
··· 39 "futures", 40 "log", 41 "reqwest", 42 "serde", 43 "serde_json", 44 - "thiserror", 45 "tokio", 46 "tokio-postgres", 47 "url", ··· 169 version = "0.22.1" 170 source = "registry+https://github.com/rust-lang/crates.io-index" 171 checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 172 173 [[package]] 174 name = "bitflags" ··· 912 ] 913 914 [[package]] 915 name = "io-uring" 916 version = "0.7.10" 917 source = "registry+https://github.com/rust-lang/crates.io-index" 918 checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" 919 dependencies = [ 920 - "bitflags", 921 "cfg-if", 922 "libc", 923 ] ··· 996 source = "registry+https://github.com/rust-lang/crates.io-index" 997 checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" 998 dependencies = [ 999 - "bitflags", 1000 "libc", 1001 - "redox_syscall", 1002 ] 1003 1004 [[package]] ··· 1133 source = "registry+https://github.com/rust-lang/crates.io-index" 1134 checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" 1135 dependencies = [ 1136 - "bitflags", 1137 "cfg-if", 1138 "foreign-types", 1139 "libc", ··· 1173 1174 [[package]] 1175 name = "parking_lot" 1176 version = "0.12.4" 1177 source = "registry+https://github.com/rust-lang/crates.io-index" 1178 checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" 1179 dependencies = [ 1180 "lock_api", 1181 - "parking_lot_core", 1182 ] 1183 1184 [[package]] ··· 1189 dependencies = [ 1190 "cfg-if", 1191 "libc", 1192 - "redox_syscall", 1193 "smallvec", 1194 "windows-targets 0.52.6", 1195 ] ··· 1264 "hmac", 1265 "md-5", 1266 "memchr", 1267 - "rand", 1268 "sha2", 1269 "stringprep", 1270 ] ··· 1327 1328 [[package]] 1329 name = "rand" 1330 version = "0.9.2" 1331 source = "registry+https://github.com/rust-lang/crates.io-index" 1332 checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" 1333 dependencies = [ 1334 - "rand_chacha", 1335 - "rand_core", 1336 ] 1337 1338 [[package]] ··· 1342 checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" 1343 dependencies = [ 1344 "ppv-lite86", 1345 - "rand_core", 1346 ] 1347 1348 [[package]] ··· 1356 1357 [[package]] 1358 name = "redox_syscall" 1359 version = "0.5.17" 1360 source = "registry+https://github.com/rust-lang/crates.io-index" 1361 checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" 1362 dependencies = [ 1363 - "bitflags", 1364 ] 1365 1366 [[package]] ··· 1436 ] 1437 1438 [[package]] 1439 name = "ring" 1440 version = "0.17.14" 1441 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1461 source = "registry+https://github.com/rust-lang/crates.io-index" 1462 checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" 1463 dependencies = [ 1464 - "bitflags", 1465 "errno", 1466 "libc", 1467 "linux-raw-sys", ··· 1534 source = "registry+https://github.com/rust-lang/crates.io-index" 1535 checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" 1536 dependencies = [ 1537 - "bitflags", 1538 "core-foundation", 1539 "core-foundation-sys", 1540 "libc", ··· 1734 source = "registry+https://github.com/rust-lang/crates.io-index" 1735 checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" 1736 dependencies = [ 1737 - "bitflags", 1738 "core-foundation", 1739 "system-configuration-sys", 1740 ] ··· 1764 1765 [[package]] 1766 name = "thiserror" 1767 version = "2.0.16" 1768 source = "registry+https://github.com/rust-lang/crates.io-index" 1769 checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" 1770 dependencies = [ 1771 - "thiserror-impl", 1772 ] 1773 1774 [[package]] ··· 1818 "io-uring", 1819 "libc", 1820 "mio", 1821 - "parking_lot", 1822 "pin-project-lite", 1823 "signal-hook-registry", 1824 "slab", ··· 1861 "futures-channel", 1862 "futures-util", 1863 "log", 1864 - "parking_lot", 1865 "percent-encoding", 1866 "phf", 1867 "pin-project-lite", 1868 "postgres-protocol", 1869 "postgres-types", 1870 - "rand", 1871 "socket2 0.5.10", 1872 "tokio", 1873 "tokio-util", ··· 1918 source = "registry+https://github.com/rust-lang/crates.io-index" 1919 checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" 1920 dependencies = [ 1921 - "bitflags", 1922 "bytes", 1923 "futures-util", 1924 "http", ··· 1949 checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" 1950 dependencies = [ 1951 "pin-project-lite", 1952 "tracing-core", 1953 ] 1954 1955 [[package]] ··· 2167 ] 2168 2169 [[package]] 2170 name = "web-sys" 2171 version = "0.3.78" 2172 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2186 "wasite", 2187 "web-sys", 2188 ] 2189 2190 [[package]] 2191 name = "windows-core"
··· 39 "futures", 40 "log", 41 "reqwest", 42 + "reqwest-middleware", 43 + "reqwest-retry", 44 "serde", 45 "serde_json", 46 + "thiserror 2.0.16", 47 "tokio", 48 "tokio-postgres", 49 "url", ··· 171 version = "0.22.1" 172 source = "registry+https://github.com/rust-lang/crates.io-index" 173 checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 174 + 175 + [[package]] 176 + name = "bitflags" 177 + version = "1.3.2" 178 + source = "registry+https://github.com/rust-lang/crates.io-index" 179 + checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 180 181 [[package]] 182 name = "bitflags" ··· 920 ] 921 922 [[package]] 923 + name = "instant" 924 + version = "0.1.13" 925 + source = "registry+https://github.com/rust-lang/crates.io-index" 926 + checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" 927 + dependencies = [ 928 + "cfg-if", 929 + "js-sys", 930 + "wasm-bindgen", 931 + "web-sys", 932 + ] 933 + 934 + [[package]] 935 name = "io-uring" 936 version = "0.7.10" 937 source = "registry+https://github.com/rust-lang/crates.io-index" 938 checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" 939 dependencies = [ 940 + "bitflags 2.9.4", 941 "cfg-if", 942 "libc", 943 ] ··· 1016 source = "registry+https://github.com/rust-lang/crates.io-index" 1017 checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" 1018 dependencies = [ 1019 + "bitflags 2.9.4", 1020 "libc", 1021 + "redox_syscall 0.5.17", 1022 ] 1023 1024 [[package]] ··· 1153 source = "registry+https://github.com/rust-lang/crates.io-index" 1154 checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" 1155 dependencies = [ 1156 + "bitflags 2.9.4", 1157 "cfg-if", 1158 "foreign-types", 1159 "libc", ··· 1193 1194 [[package]] 1195 name = "parking_lot" 1196 + version = "0.11.2" 1197 + source = "registry+https://github.com/rust-lang/crates.io-index" 1198 + checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" 1199 + dependencies = [ 1200 + "instant", 1201 + "lock_api", 1202 + "parking_lot_core 0.8.6", 1203 + ] 1204 + 1205 + [[package]] 1206 + name = "parking_lot" 1207 version = "0.12.4" 1208 source = "registry+https://github.com/rust-lang/crates.io-index" 1209 checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" 1210 dependencies = [ 1211 "lock_api", 1212 + "parking_lot_core 0.9.11", 1213 + ] 1214 + 1215 + [[package]] 1216 + name = "parking_lot_core" 1217 + version = "0.8.6" 1218 + source = "registry+https://github.com/rust-lang/crates.io-index" 1219 + checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" 1220 + dependencies = [ 1221 + "cfg-if", 1222 + "instant", 1223 + "libc", 1224 + "redox_syscall 0.2.16", 1225 + "smallvec", 1226 + "winapi", 1227 ] 1228 1229 [[package]] ··· 1234 dependencies = [ 1235 "cfg-if", 1236 "libc", 1237 + "redox_syscall 0.5.17", 1238 "smallvec", 1239 "windows-targets 0.52.6", 1240 ] ··· 1309 "hmac", 1310 "md-5", 1311 "memchr", 1312 + "rand 0.9.2", 1313 "sha2", 1314 "stringprep", 1315 ] ··· 1372 1373 [[package]] 1374 name = "rand" 1375 + version = "0.8.5" 1376 + source = "registry+https://github.com/rust-lang/crates.io-index" 1377 + checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" 1378 + dependencies = [ 1379 + "libc", 1380 + "rand_chacha 0.3.1", 1381 + "rand_core 0.6.4", 1382 + ] 1383 + 1384 + [[package]] 1385 + name = "rand" 1386 version = "0.9.2" 1387 source = "registry+https://github.com/rust-lang/crates.io-index" 1388 checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" 1389 dependencies = [ 1390 + "rand_chacha 0.9.0", 1391 + "rand_core 0.9.3", 1392 + ] 1393 + 1394 + [[package]] 1395 + name = "rand_chacha" 1396 + version = "0.3.1" 1397 + source = "registry+https://github.com/rust-lang/crates.io-index" 1398 + checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" 1399 + dependencies = [ 1400 + "ppv-lite86", 1401 + "rand_core 0.6.4", 1402 ] 1403 1404 [[package]] ··· 1408 checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" 1409 dependencies = [ 1410 "ppv-lite86", 1411 + "rand_core 0.9.3", 1412 + ] 1413 + 1414 + [[package]] 1415 + name = "rand_core" 1416 + version = "0.6.4" 1417 + source = "registry+https://github.com/rust-lang/crates.io-index" 1418 + checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" 1419 + dependencies = [ 1420 + "getrandom 0.2.16", 1421 ] 1422 1423 [[package]] ··· 1431 1432 [[package]] 1433 name = "redox_syscall" 1434 + version = "0.2.16" 1435 + source = "registry+https://github.com/rust-lang/crates.io-index" 1436 + checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 1437 + dependencies = [ 1438 + "bitflags 1.3.2", 1439 + ] 1440 + 1441 + [[package]] 1442 + name = "redox_syscall" 1443 version = "0.5.17" 1444 source = "registry+https://github.com/rust-lang/crates.io-index" 1445 checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" 1446 dependencies = [ 1447 + "bitflags 2.9.4", 1448 ] 1449 1450 [[package]] ··· 1520 ] 1521 1522 [[package]] 1523 + name = "reqwest-middleware" 1524 + version = "0.4.2" 1525 + source = "registry+https://github.com/rust-lang/crates.io-index" 1526 + checksum = "57f17d28a6e6acfe1733fe24bcd30774d13bffa4b8a22535b4c8c98423088d4e" 1527 + dependencies = [ 1528 + "anyhow", 1529 + "async-trait", 1530 + "http", 1531 + "reqwest", 1532 + "serde", 1533 + "thiserror 1.0.69", 1534 + "tower-service", 1535 + ] 1536 + 1537 + [[package]] 1538 + name = "reqwest-retry" 1539 + version = "0.7.0" 1540 + source = "registry+https://github.com/rust-lang/crates.io-index" 1541 + checksum = "29c73e4195a6bfbcb174b790d9b3407ab90646976c55de58a6515da25d851178" 1542 + dependencies = [ 1543 + "anyhow", 1544 + "async-trait", 1545 + "futures", 1546 + "getrandom 0.2.16", 1547 + "http", 1548 + "hyper", 1549 + "parking_lot 0.11.2", 1550 + "reqwest", 1551 + "reqwest-middleware", 1552 + "retry-policies", 1553 + "thiserror 1.0.69", 1554 + "tokio", 1555 + "tracing", 1556 + "wasm-timer", 1557 + ] 1558 + 1559 + [[package]] 1560 + name = "retry-policies" 1561 + version = "0.4.0" 1562 + source = "registry+https://github.com/rust-lang/crates.io-index" 1563 + checksum = "5875471e6cab2871bc150ecb8c727db5113c9338cc3354dc5ee3425b6aa40a1c" 1564 + dependencies = [ 1565 + "rand 0.8.5", 1566 + ] 1567 + 1568 + [[package]] 1569 name = "ring" 1570 version = "0.17.14" 1571 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1591 source = "registry+https://github.com/rust-lang/crates.io-index" 1592 checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" 1593 dependencies = [ 1594 + "bitflags 2.9.4", 1595 "errno", 1596 "libc", 1597 "linux-raw-sys", ··· 1664 source = "registry+https://github.com/rust-lang/crates.io-index" 1665 checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" 1666 dependencies = [ 1667 + "bitflags 2.9.4", 1668 "core-foundation", 1669 "core-foundation-sys", 1670 "libc", ··· 1864 source = "registry+https://github.com/rust-lang/crates.io-index" 1865 checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" 1866 dependencies = [ 1867 + "bitflags 2.9.4", 1868 "core-foundation", 1869 "system-configuration-sys", 1870 ] ··· 1894 1895 [[package]] 1896 name = "thiserror" 1897 + version = "1.0.69" 1898 + source = "registry+https://github.com/rust-lang/crates.io-index" 1899 + checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" 1900 + dependencies = [ 1901 + "thiserror-impl 1.0.69", 1902 + ] 1903 + 1904 + [[package]] 1905 + name = "thiserror" 1906 version = "2.0.16" 1907 source = "registry+https://github.com/rust-lang/crates.io-index" 1908 checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" 1909 dependencies = [ 1910 + "thiserror-impl 2.0.16", 1911 + ] 1912 + 1913 + [[package]] 1914 + name = "thiserror-impl" 1915 + version = "1.0.69" 1916 + source = "registry+https://github.com/rust-lang/crates.io-index" 1917 + checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" 1918 + dependencies = [ 1919 + "proc-macro2", 1920 + "quote", 1921 + "syn", 1922 ] 1923 1924 [[package]] ··· 1968 "io-uring", 1969 "libc", 1970 "mio", 1971 + "parking_lot 0.12.4", 1972 "pin-project-lite", 1973 "signal-hook-registry", 1974 "slab", ··· 2011 "futures-channel", 2012 "futures-util", 2013 "log", 2014 + "parking_lot 0.12.4", 2015 "percent-encoding", 2016 "phf", 2017 "pin-project-lite", 2018 "postgres-protocol", 2019 "postgres-types", 2020 + "rand 0.9.2", 2021 "socket2 0.5.10", 2022 "tokio", 2023 "tokio-util", ··· 2068 source = "registry+https://github.com/rust-lang/crates.io-index" 2069 checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" 2070 dependencies = [ 2071 + "bitflags 2.9.4", 2072 "bytes", 2073 "futures-util", 2074 "http", ··· 2099 checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" 2100 dependencies = [ 2101 "pin-project-lite", 2102 + "tracing-attributes", 2103 "tracing-core", 2104 + ] 2105 + 2106 + [[package]] 2107 + name = "tracing-attributes" 2108 + version = "0.1.30" 2109 + source = "registry+https://github.com/rust-lang/crates.io-index" 2110 + checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" 2111 + dependencies = [ 2112 + "proc-macro2", 2113 + "quote", 2114 + "syn", 2115 ] 2116 2117 [[package]] ··· 2329 ] 2330 2331 [[package]] 2332 + name = "wasm-timer" 2333 + version = "0.2.5" 2334 + source = "registry+https://github.com/rust-lang/crates.io-index" 2335 + checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" 2336 + dependencies = [ 2337 + "futures", 2338 + "js-sys", 2339 + "parking_lot 0.11.2", 2340 + "pin-utils", 2341 + "wasm-bindgen", 2342 + "wasm-bindgen-futures", 2343 + "web-sys", 2344 + ] 2345 + 2346 + [[package]] 2347 name = "web-sys" 2348 version = "0.3.78" 2349 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2363 "wasite", 2364 "web-sys", 2365 ] 2366 + 2367 + [[package]] 2368 + name = "winapi" 2369 + version = "0.3.9" 2370 + source = "registry+https://github.com/rust-lang/crates.io-index" 2371 + checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 2372 + dependencies = [ 2373 + "winapi-i686-pc-windows-gnu", 2374 + "winapi-x86_64-pc-windows-gnu", 2375 + ] 2376 + 2377 + [[package]] 2378 + name = "winapi-i686-pc-windows-gnu" 2379 + version = "0.4.0" 2380 + source = "registry+https://github.com/rust-lang/crates.io-index" 2381 + checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 2382 + 2383 + [[package]] 2384 + name = "winapi-x86_64-pc-windows-gnu" 2385 + version = "0.4.0" 2386 + source = "registry+https://github.com/rust-lang/crates.io-index" 2387 + checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 2388 2389 [[package]] 2390 name = "windows-core"
+2
Cargo.toml
··· 14 futures = "0.3.31" 15 log = "0.4.28" 16 reqwest = { version = "0.12.23", features = ["stream"] } 17 serde = "1.0.219" 18 serde_json = { version = "1.0.143", features = ["raw_value"] } 19 thiserror = "2.0.16"
··· 14 futures = "0.3.31" 15 log = "0.4.28" 16 reqwest = { version = "0.12.23", features = ["stream"] } 17 + reqwest-middleware = "0.4.2" 18 + reqwest-retry = "0.7.0" 19 serde = "1.0.219" 20 serde_json = { version = "1.0.143", features = ["raw_value"] } 21 thiserror = "2.0.16"
+11 -3
src/client.rs
··· 1 use reqwest::Client; 2 use std::sync::LazyLock; 3 4 - pub static CLIENT: LazyLock<Client> = LazyLock::new(|| { 5 - Client::builder() 6 .user_agent(concat!( 7 "allegedly, v", 8 env!("CARGO_PKG_VERSION"), 9 " (from @microcosm.blue; contact @bad-example.com)" 10 )) 11 .build() 12 - .unwrap() 13 });
··· 1 use reqwest::Client; 2 + use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; 3 + use reqwest_retry::{RetryTransientMiddleware, policies::ExponentialBackoff}; 4 use std::sync::LazyLock; 5 6 + pub static CLIENT: LazyLock<ClientWithMiddleware> = LazyLock::new(|| { 7 + let inner = Client::builder() 8 .user_agent(concat!( 9 "allegedly, v", 10 env!("CARGO_PKG_VERSION"), 11 " (from @microcosm.blue; contact @bad-example.com)" 12 )) 13 .build() 14 + .unwrap(); 15 + 16 + let policy = ExponentialBackoff::builder().build_with_max_retries(12); 17 + 18 + ClientBuilder::new(inner) 19 + .with(RetryTransientMiddleware::new_with_policy(policy)) 20 + .build() 21 });
+4 -2
src/poll.rs
··· 8 #[derive(Debug, Error)] 9 pub enum GetPageError { 10 #[error(transparent)] 11 - ReqwestError(#[from] reqwest::Error), 12 #[error(transparent)] 13 - SerdeError(#[from] serde_json::Error), 14 } 15 16 /// ops are primary-keyed by (did, cid)
··· 8 #[derive(Debug, Error)] 9 pub enum GetPageError { 10 #[error(transparent)] 11 + Reqwest(#[from] reqwest::Error), 12 #[error(transparent)] 13 + ReqwestMiddleware(#[from] reqwest_middleware::Error), 14 + #[error(transparent)] 15 + Serde(#[from] serde_json::Error), 16 } 17 18 /// ops are primary-keyed by (did, cid)