From a1cb2bd1108107834213a28a11c4ef03fc162eca Mon Sep 17 00:00:00 2001 From: max funk Date: Sat, 16 Nov 2024 17:11:48 -0700 Subject: [PATCH 1/6] reset websocket as function in client --- client/src/routes/measure/+page.svelte | 47 +++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/client/src/routes/measure/+page.svelte b/client/src/routes/measure/+page.svelte index 9a3d88c4..e450ad07 100644 --- a/client/src/routes/measure/+page.svelte +++ b/client/src/routes/measure/+page.svelte @@ -3,14 +3,14 @@ import { onMount } from 'svelte'; import b64 from 'base-64'; import { createClient as createWSClient } from 'graphql-ws'; - + import type { Client } from 'graphql-ws'; let searchQuery = ''; - let price = 0.0; + let price: string; let priceTag: HTMLDivElement; let map: google.maps.Map; let markers = [] as any[]; // todo: google.maps.marker.AdvancedMarkerElement does not expect setMap method let messageCount = 0; - let wsClient: any = null; // todo: graphql-ws Client type + let wsClient: Client; let stop = false; let defaultCoordinates = { lat: 39.8283, lng: -98.5795 }; // usa @@ -20,39 +20,36 @@ region: string, municipality: string | null ) { - if (wsClient) { - stop = true; - } else { - wsClient = createWSClient({ + + if (messageCount) { + await resetWebsocket(); + } + + wsClient = createWSClient({ url: b64.decode(process.env.GRAPHQL_SUBSCRIPTIONS_URI as string), - lazy: false }); - } const variables: any = { date, country, region }; if (municipality) { variables.municipality = municipality; } - let subscription = wsClient.iterate({ + const subscription = wsClient.iterate({ query: `subscription QueryGdp($date: String!, $country: String, $region: String, $municipality: String) { queryGdp(date: $date, country: $country, region: $region, municipality: $municipality) }`, variables }); - messageCount = 0; for await (const { data } of subscription) { if (stop) { - // console.log('stopping subscription'); stop = false; break; } - if (messageCount == 0) { - // console.log('starting subscription'); + if (data && typeof data.queryGdp === 'number') { + price = data.queryGdp.toFixed(3); + messageCount++; } - messageCount++; - price = data.queryGdp.toFixed(3); } } @@ -66,7 +63,7 @@ event.preventDefault(); if (searchQuery.trim() === '') { - resetMap(); + await resetMap(); return; } @@ -89,6 +86,15 @@ await subscribeGdp(queryVars.time, queryVars.country, queryVars.region, queryVars.municipality); } + async function resetWebsocket() { + stop = true; + // wait for subscription loop to break + while (stop) { + await new Promise((resolve) => setTimeout(resolve, 100)); + } + messageCount = 0; + } + function toTitleCase(str: string) { return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); @@ -138,8 +144,9 @@ }, 100); // check every 100 milliseconds } - function resetMap() { + async function resetMap() { if (map) { + await resetWebsocket(); markers.forEach((marker) => marker.setMap(null)); markers = []; map.setCenter(defaultCoordinates); @@ -210,13 +217,13 @@ priceTag.appendChild(pseudoElement); - const market = new AdvancedMarkerElement({ + const marker = new AdvancedMarkerElement({ map, position: location, content: priceTag }); - markers.push(market); + markers.push(marker); waitForMessages(); } else { From 31843bf701ff1edd1be39756f3e8f5c9fe83437a Mon Sep 17 00:00:00 2001 From: max funk Date: Sat, 16 Nov 2024 17:12:13 -0700 Subject: [PATCH 2/6] logging vars --- project.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/project.yaml b/project.yaml index dbf4cc72..61b5da01 100644 --- a/project.yaml +++ b/project.yaml @@ -447,6 +447,7 @@ services: - GRAPHQL_PORT - MEASURE_URL - MEASURE_RESOURCE + - RUST_LOG request-create: runtime: rust1.x min_code_cov: null @@ -518,7 +519,8 @@ services: default: localhost RUST_LOG: ssm: null - default: info + # https://docs.rs/env_logger/latest/env_logger/#enabling-logging + default: off RUST_BACKTRACE: ssm: null default: 1 @@ -724,6 +726,7 @@ services: - REDIS_PASSWORD - MEASURE_PORT - READINESS_CHECK_PATH + - RUST_LOG auto-confirm: runtime: rust1.x min_code_cov: null From 7f15a67dfb356953a0cc8d3ad917a999b4f5b1fd Mon Sep 17 00:00:00 2001 From: max funk Date: Sat, 16 Nov 2024 17:12:43 -0700 Subject: [PATCH 3/6] cargo lock --- Cargo.lock | 392 +++++++++++++++++++++++++++-------------------------- 1 file changed, 197 insertions(+), 195 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6f854f8..4117a75f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,7 +172,7 @@ dependencies = [ "async-lock 3.2.0", "async-task", "concurrent-queue", - "fastrand 2.0.1", + "fastrand 2.1.1", "futures-lite 2.2.0", "slab", ] @@ -194,23 +194,24 @@ dependencies = [ [[package]] name = "async-graphql" -version = "7.0.0" +version = "7.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad990024653fd2d0321a568f64e620404a894047b2ab8c475f7452c8bb82cf6" +checksum = "0ba6d24703c5adc5ba9116901b92ee4e4c0643c01a56c4fd303f3818638d7449" dependencies = [ "async-graphql-derive", "async-graphql-parser", "async-graphql-value", "async-stream", "async-trait", - "base64 0.13.1", + "base64 0.22.1", "bytes", "chrono", "fast_chemail", "fnv", + "futures-timer", "futures-util", "handlebars", - "http 1.0.0", + "http 1.1.0", "indexmap 2.1.0", "mime", "multer", @@ -221,16 +222,16 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "static_assertions", + "static_assertions_next", "tempfile", "thiserror", ] [[package]] name = "async-graphql-axum" -version = "7.0.0" +version = "7.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1c9aed04854fb55a9d3fbab94e013cfc7ca5e3cead0b49b439884f8a467039" +checksum = "e9aa80e171205c6d562057fd5a49167c8fbe61f7db2bed6540f6d4f2234d7ff2" dependencies = [ "async-graphql", "async-trait", @@ -246,26 +247,26 @@ dependencies = [ [[package]] name = "async-graphql-derive" -version = "7.0.0" +version = "7.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3909cc7228128099b603d057e5a920b9499ce24299f8f680d5d1f213d7b830c0" +checksum = "a94c2d176893486bd37cd1b6defadd999f7357bf5804e92f510c08bcf16c538f" dependencies = [ "Inflector", "async-graphql-parser", - "darling 0.20.3", - "proc-macro-crate 1.3.1", + "darling 0.20.10", + "proc-macro-crate", "proc-macro2", "quote", - "strum 0.25.0", + "strum 0.26.3", "syn 2.0.48", "thiserror", ] [[package]] name = "async-graphql-parser" -version = "7.0.0" +version = "7.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ceb02570faf16e3b6775cc286b1f0fb2e4eb846144a08c130ca5ad6e25219fe" +checksum = "79272bdbf26af97866e149f05b2b546edb5c00e51b5f916289931ed233e208ad" dependencies = [ "async-graphql-value", "pest", @@ -275,9 +276,9 @@ dependencies = [ [[package]] name = "async-graphql-value" -version = "7.0.0" +version = "7.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "516317bb55d143cc47941c0cb952134dd207c5ab3c839ee226eedd6dd9a96f43" +checksum = "ef5ec94176a12a8cbe985cd73f2e54dc9c702c88c766bdef12f1f3a67cedbee1" dependencies = [ "bytes", "indexmap 2.1.0", @@ -318,7 +319,7 @@ dependencies = [ "futures-lite 2.2.0", "parking", "polling 3.3.1", - "rustix 0.38.21", + "rustix 0.38.37", "slab", "tracing", "windows-sys 0.52.0", @@ -366,7 +367,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.21", + "rustix 0.38.37", "windows-sys 0.48.0", ] @@ -382,7 +383,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.21", + "rustix 0.38.37", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -446,9 +447,9 @@ checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", @@ -515,7 +516,7 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "fastrand 2.0.1", + "fastrand 2.1.1", "hex", "http 0.2.9", "hyper 0.14.28", @@ -568,7 +569,7 @@ dependencies = [ "aws-smithy-runtime-api", "aws-smithy-types", "aws-types", - "fastrand 2.0.1", + "fastrand 2.1.1", "http 0.2.9", "percent-encoding", "tracing", @@ -728,7 +729,7 @@ dependencies = [ "aws-smithy-runtime-api", "aws-smithy-types", "bytes", - "fastrand 2.0.1", + "fastrand 2.1.1", "h2", "http 0.2.9", "http-body 0.4.5", @@ -811,7 +812,7 @@ checksum = "c25e7620d59c7a9ed653439ec402218e3f6be118000f92802c5bbfc6da98e65b" dependencies = [ "base64 0.21.5", "bytes", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-serde", "query_map", @@ -874,7 +875,7 @@ dependencies = [ "base64 0.21.5", "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "hyper 1.4.1", @@ -926,7 +927,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "mime", @@ -980,6 +981,12 @@ version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64-simd" version = "0.8.0" @@ -1083,7 +1090,7 @@ dependencies = [ "async-channel 2.1.1", "async-lock 3.2.0", "async-task", - "fastrand 2.0.1", + "fastrand 2.1.1", "futures-io", "futures-lite 2.2.0", "piper", @@ -1107,7 +1114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7aadb5b6ccbd078890f6d7003694e33816e6b784358f18e15e7e6d9f065a57cd" dependencies = [ "once_cell", - "proc-macro-crate 3.1.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.48", @@ -1200,7 +1207,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.0", + "windows-targets 0.52.6", ] [[package]] @@ -1382,12 +1389,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.3" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ - "darling_core 0.20.3", - "darling_macro 0.20.3", + "darling_core 0.20.10", + "darling_macro 0.20.10", ] [[package]] @@ -1400,21 +1407,21 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", ] [[package]] name = "darling_core" -version = "0.20.3" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.11.1", "syn 2.0.48", ] @@ -1431,11 +1438,11 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.3" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ - "darling_core 0.20.3", + "darling_core 0.20.10", "quote", "syn 2.0.48", ] @@ -1571,6 +1578,8 @@ dependencies = [ "serde_json", "tokio", "tokio-postgres", + "tracing", + "tracing-subscriber", ] [[package]] @@ -1649,9 +1658,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fixedbitset" @@ -1811,7 +1820,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba" dependencies = [ - "fastrand 2.0.1", + "fastrand 2.1.1", "futures-core", "futures-io", "parking", @@ -1841,6 +1850,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + [[package]] name = "futures-util" version = "0.3.30" @@ -1931,9 +1946,8 @@ dependencies = [ "aws_lambda_events 0.13.0", "axum 0.7.5", "futures-util", - "http 1.0.0", + "http 1.1.0", "httpclient", - "log", "openssl", "serde_json", "shutdown", @@ -1984,7 +1998,7 @@ checksum = "a40f793251171991c4eb75bd84bc640afa8b68ff6907bc89d3b712a22f700506" dependencies = [ "graphql-introspection-query", "graphql-parser", - "heck", + "heck 0.4.1", "lazy_static", "proc-macro2", "quote", @@ -2025,9 +2039,9 @@ dependencies = [ [[package]] name = "handlebars" -version = "4.5.0" +version = "5.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faa67bab9ff362228eb3d00bd024a4965d8231bbb7921167f0cfa66c6626b225" +checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b" dependencies = [ "log", "pest", @@ -2068,19 +2082,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "hermit-abi" -version = "0.2.6" +name = "heck" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -2110,9 +2121,9 @@ dependencies = [ [[package]] name = "http" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -2137,7 +2148,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http 1.0.0", + "http 1.1.0", ] [[package]] @@ -2148,7 +2159,7 @@ checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "pin-project-lite", ] @@ -2165,7 +2176,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fb7239a6d49eda628c2dfdd7e982c59b0c3f0fb99ce45c4237f02a520030688" dependencies = [ - "http 1.0.0", + "http 1.1.0", "serde", ] @@ -2257,7 +2268,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "httparse", "httpdate", @@ -2306,7 +2317,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "hyper 1.4.1", "pin-project-lite", @@ -2394,7 +2405,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi", "libc", "windows-sys 0.48.0", ] @@ -2411,8 +2422,8 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ - "hermit-abi 0.3.3", - "rustix 0.38.21", + "hermit-abi", + "rustix 0.38.37", "windows-sys 0.52.0", ] @@ -2505,7 +2516,7 @@ dependencies = [ "base64 0.21.5", "bytes", "futures", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "http-serde", @@ -2530,7 +2541,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "hyper 1.4.1", @@ -2556,9 +2567,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" [[package]] name = "libc" -version = "0.2.149" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libmath" @@ -2597,9 +2608,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.12" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -2651,7 +2662,7 @@ dependencies = [ "axum 0.7.5", "fred", "futures", - "http 1.0.0", + "http 1.1.0", "pg", "rust_decimal", "serde", @@ -2669,9 +2680,9 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minimal-lexical" @@ -2690,13 +2701,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.10" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2735,7 +2747,7 @@ dependencies = [ "bytes", "encoding_rs", "futures-util", - "http 1.0.0", + "http 1.1.0", "httparse", "log", "memchr", @@ -2826,23 +2838,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg 1.1.0", ] -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi 0.2.6", - "libc", -] - [[package]] name = "object" version = "0.32.1" @@ -2971,9 +2973,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.6" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" +checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", "thiserror", @@ -3094,9 +3096,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -3111,7 +3113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" dependencies = [ "atomic-waker", - "fastrand 2.0.1", + "fastrand 2.1.1", "futures-io", ] @@ -3146,7 +3148,7 @@ dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", - "rustix 0.38.21", + "rustix 0.38.37", "tracing", "windows-sys 0.52.0", ] @@ -3157,7 +3159,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83145eba741b050ef981a9a1838c843fa7665e154383325aa8b440ae703180a2" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "syn 2.0.48", @@ -3240,23 +3242,13 @@ dependencies = [ "termtree", ] -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit 0.19.15", -] - [[package]] name = "proc-macro-crate" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_edit 0.21.1", + "toml_edit", ] [[package]] @@ -3284,9 +3276,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -3550,14 +3542,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.5", - "regex-syntax 0.8.2", + "regex-automata 0.4.8", + "regex-syntax 0.8.5", ] [[package]] @@ -3571,13 +3563,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax 0.8.5", ] [[package]] @@ -3594,9 +3586,9 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rend" @@ -3818,15 +3810,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.21" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.12", - "windows-sys 0.48.0", + "linux-raw-sys 0.4.14", + "windows-sys 0.52.0", ] [[package]] @@ -3992,11 +3984,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -4227,10 +4220,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] -name = "static_assertions" -version = "1.1.0" +name = "static_assertions_next" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" [[package]] name = "string_cache" @@ -4261,6 +4254,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.24.1" @@ -4272,11 +4271,11 @@ dependencies = [ [[package]] name = "strum" -version = "0.25.0" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ - "strum_macros 0.25.3", + "strum_macros 0.26.4", ] [[package]] @@ -4285,7 +4284,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -4294,11 +4293,11 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.25.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "rustversion", @@ -4386,15 +4385,15 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.8.1" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", - "fastrand 2.0.1", - "redox_syscall 0.4.1", - "rustix 0.38.21", - "windows-sys 0.48.0", + "fastrand 2.1.1", + "once_cell", + "rustix 0.38.37", + "windows-sys 0.59.0", ] [[package]] @@ -4441,18 +4440,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -4526,28 +4525,27 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2 0.5.5", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -4623,9 +4621,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.7" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -4633,7 +4631,6 @@ dependencies = [ "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -4642,17 +4639,6 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.1.0", - "toml_datetime", - "winnow", -] - [[package]] name = "toml_edit" version = "0.21.1" @@ -4707,7 +4693,7 @@ checksum = "0da193277a4e2c33e59e09b5861580c33dd0a637c3883d0fa74ba40c0374af2e" dependencies = [ "bitflags 2.4.0", "bytes", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "pin-project-lite", @@ -4847,7 +4833,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http 1.0.0", + "http 1.1.0", "httparse", "log", "rand 0.8.5", @@ -4866,7 +4852,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http 1.0.0", + "http 1.1.0", "httparse", "log", "rand 0.8.5", @@ -5190,7 +5176,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -5225,17 +5220,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -5252,9 +5248,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -5270,9 +5266,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -5288,9 +5284,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -5306,9 +5308,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -5324,9 +5326,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -5342,9 +5344,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -5360,9 +5362,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" From ea55d42e1462453363112568536d4bc5f463325a Mon Sep 17 00:00:00 2001 From: max funk Date: Sat, 16 Nov 2024 17:32:23 -0700 Subject: [PATCH 4/6] job faq --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 610b80bc..df60f402 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,11 @@ removing financial appeasement guides the freedom of speech by recalibrating exp **q.** how does systemaccounting affect setting public policy? **a.** solving problems one at a time depends on 1) researching facts, 2) designing a solution, 3) applying the solution, 4) measuring its input and output and 5) holding contributors accountable. empowering sincere fact finders and problem solvers with more convenient access to public data science reduces the risk of luring them into the idle game of assigning blame between fictional social groups +**q.** how does systemaccounting create jobs? +**a.** the demand for labor increases when capital is allocated. for example, when an investor can quickly and confidently find a profitable grocery store chain and supply the owner capital to open more stores, the owner will hire more labor. systemaccounting accelerates the movement of capital by setting the measure of its demand to the conveniently discoverable and empirical supply of return + +on the other hand, systemaccounting will eliminate a lot of archaic labor dependent on market friction in the short term and manual labor dependent on highly repetitive work in the long term (automation attracts capital). [be patient](https://gist.github.com/mxfactorial/e127115f4e9d240dd992cfc0920d1527) + **q.** do you have any demos? **a.** watch the [economic policy as code](https://mxfactorial.video/) video series From 26763b835f7148863fb3981af517e225045af876 Mon Sep 17 00:00:00 2001 From: max funk Date: Sat, 16 Nov 2024 17:33:16 -0700 Subject: [PATCH 5/6] add logging --- services/event/Cargo.toml | 2 ++ services/event/src/main.rs | 23 +++++++++++++++-------- services/measure/src/main.rs | 36 ++++++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/services/event/Cargo.toml b/services/event/Cargo.toml index eed1d6b9..ee4e24fc 100644 --- a/services/event/Cargo.toml +++ b/services/event/Cargo.toml @@ -13,3 +13,5 @@ serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.93" fred = { version = "9.0.3", features = ["i-scripts"] } rust_decimal = "1.36.0" +tracing = "0.1.40" +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } \ No newline at end of file diff --git a/services/event/src/main.rs b/services/event/src/main.rs index 64147bad..9141b2ac 100644 --- a/services/event/src/main.rs +++ b/services/event/src/main.rs @@ -2,6 +2,7 @@ use fred::prelude::*; use futures_channel::mpsc; use futures_util::{stream, FutureExt, StreamExt, TryStreamExt}; use serde::Deserialize; +use std::env; use tokio_postgres::{AsyncMessage, NoTls}; mod events; @@ -46,6 +47,12 @@ struct Event { #[tokio::main] async fn main() { + if let Ok(level) = env::var("RUST_LOG") { + tracing_subscriber::fmt().with_env_filter(level).init(); + } else { + tracing_subscriber::fmt().init(); + } + let pg_uri = pg_conn_uri(); let redis_uri = redis_conn_uri(); let redis_config = RedisConfig::from_url(&redis_uri).unwrap(); @@ -54,11 +61,11 @@ async fn main() { loop { match redis_client.init().await { Ok(_) => { - // println!("event connected to redis"); + tracing::info!("event connected to redis"); break; } Err(_e) => { - // println!("failed to connect to redis: {}", _e); + tracing::info!("failed to connect to redis: {}", _e); tokio::time::sleep(std::time::Duration::from_secs(5)).await; } } @@ -68,7 +75,7 @@ async fn main() { let (client, mut connection) = match tokio_postgres::connect(pg_uri.as_str(), NoTls).await { Ok(conn) => conn, Err(_e) => { - // println!("failed to connect to postgres: {}", _e); + tracing::info!("failed to connect to postgres: {}", _e); tokio::time::sleep(std::time::Duration::from_secs(5)).await; continue; } @@ -82,7 +89,7 @@ async fn main() { let handler = tokio::spawn(connection); if let Err(e) = client.batch_execute("LISTEN event;").await { - println!("failed to execute LISTEN command: {}", e); + tracing::info!("failed to execute LISTEN command: {}", e); handler.abort(); continue; } @@ -91,7 +98,7 @@ async fn main() { let message = match rx.next().await { Some(message) => message, None => { - // println!("connection terminated. attempting to reconnect..."); + tracing::info!("connection terminated. attempting to reconnect..."); handler.abort(); break; } @@ -105,15 +112,15 @@ async fn main() { events::redis_incrby_gdp(&redis_client, gdp_map).await; } _ => { - println!("unknown event: {}", event.name); + tracing::info!("unknown event: {}", event.name); } }, Err(e) => { - println!("failed to parse event: {}", e); + tracing::info!("failed to parse event: {}", e); } }, _ => { - println!("unhandled message: {:?}", message); + tracing::info!("unhandled message: {:?}", message); tokio::time::sleep(std::time::Duration::from_secs(1)).await; continue; } diff --git a/services/measure/src/main.rs b/services/measure/src/main.rs index f351fc83..7b6fd88e 100644 --- a/services/measure/src/main.rs +++ b/services/measure/src/main.rs @@ -69,9 +69,11 @@ impl Params { #[tokio::main] async fn main() { - tracing_subscriber::fmt() - .with_max_level(tracing::Level::INFO) - .init(); + if let Ok(level) = env::var("RUST_LOG") { + tracing_subscriber::fmt().with_env_filter(level).init(); + } else { + tracing_subscriber::fmt().init(); + } let readiness_check_path = env::var(READINESS_CHECK_PATH) .unwrap_or_else(|_| panic!("{READINESS_CHECK_PATH} variable assignment")); @@ -144,10 +146,8 @@ async fn proxy_redis_subscription(redis_client: RedisClient, socket: WebSocket) loop { tokio::select! { ws_msg = ws_rx.next() => { - if let Some(Ok(Message::Close(_))) = ws_msg { - break; - } if ws_msg.is_none() { + tracing::error!("measure received empty message from graphql"); break; } }, @@ -155,13 +155,20 @@ async fn proxy_redis_subscription(redis_client: RedisClient, socket: WebSocket) match redis_msg { Ok(message) => { let message = message.value.as_string().unwrap(); - let item = Message::Text(trim_string_decimal(message.as_str())); - if ws_tx.send(item).await.is_err() { - break; + let gdp = trim_string_decimal(message.as_str()); + let msg = Message::Text(gdp.clone()); + match ws_tx.send(msg).await { + Ok(_) => { + tracing::info!("message sent to graphql: {}", gdp); + }, + Err(e) => { + tracing::error!("error sending message to graphql: {}", e); + break; + } } } Err(e) => { - tracing::error!("error receiving message: {}", e); + tracing::error!("error receiving message from graphql: {}", e); break; } } @@ -169,8 +176,13 @@ async fn proxy_redis_subscription(redis_client: RedisClient, socket: WebSocket) } } - if let Err(e) = ws_tx.close().await { - tracing::error!("error closing websocket: {}", e); + match ws_tx.close().await { + Ok(_) => { + tracing::info!("websocket with graphql closed"); + } + Err(e) => { + tracing::error!("error closing websocket with graphql: {}", e); + } } } From 21cb268177ebf721f4d96a6d312e95919214b735 Mon Sep 17 00:00:00 2001 From: max funk Date: Sat, 16 Nov 2024 17:35:39 -0700 Subject: [PATCH 6/6] throttle reads from measure service allows graphql to handle close message from client --- services/graphql/Cargo.toml | 1 - services/graphql/src/main.rs | 27 ++++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/services/graphql/Cargo.toml b/services/graphql/Cargo.toml index ce0631cf..9526d6fa 100644 --- a/services/graphql/Cargo.toml +++ b/services/graphql/Cargo.toml @@ -24,7 +24,6 @@ futures-util = "0.3.30" wsclient = { path = "../../crates/wsclient" } tungstenite = { version = "0.24.0", default-features = false } async-stream = "0.3.5" -log = "0.4.22" [target.x86_64-unknown-linux-musl.dependencies] # https://github.com/cross-rs/cross/wiki/Recipes#vendored diff --git a/services/graphql/src/main.rs b/services/graphql/src/main.rs index a7958797..0ac9eb4d 100644 --- a/services/graphql/src/main.rs +++ b/services/graphql/src/main.rs @@ -18,7 +18,6 @@ use axum::{ }; use futures_util::stream::Stream; use httpclient::HttpClient as Client; -use log::debug; use serde_json::json; use shutdown::shutdown_signal; use std::{env, net::ToSocketAddrs, result::Result}; @@ -202,42 +201,43 @@ impl Subscription { let resource = env::var("MEASURE_RESOURCE").unwrap(); let uri = format!("{}/{}", base_uri, resource); let ws_client = WsClient::new(uri, "gdp".to_string(), date, country, region, municipality); - stream! { let mut measure_socket = match ws_client.connect() { Ok(ws) => { - debug!("measure websocket connection created"); + tracing::info!("graphql websocket connection created with measure"); ws } Err(_e) => { - debug!("measure webSocket connection failure: {:?}", _e); + tracing::info!("graphql failed to create webSocket with measure: {:?}", _e); return; } }; - loop { match measure_socket.read() { Ok(msg) => { match msg { tungstenite::Message::Text(text) => { let gdp: f64 = serde_json::from_str(&text).unwrap(); + tracing::info!("sending gdp from measure: {}", gdp); yield gdp; } _ => { - debug!("received non-text message: {:?}", msg); + tracing::info!("received non-text message from measure: {:?}", msg); } } } Err(WsError::ConnectionClosed) => { measure_socket.close(None).unwrap(); - debug!("measure websocket closed"); + tracing::info!("graphql received closed message from measure"); break; } Err(e) => { - debug!("measure message receipt failure: {:?}", e); + tracing::info!("graphql message receipt failure from measure: {:?}", e); break; } } + // throttle reads from measure service to avoid blocking close messages from client + tokio::time::sleep(tokio::time::Duration::from_millis(10)).await; } } } @@ -305,17 +305,22 @@ async fn graphql_subscription( ) -> impl IntoResponse { ws.protocols(http::ALL_WEBSOCKET_PROTOCOLS) .on_upgrade(move |socket| async move { - // println!("connection opened"); + tracing::info!("graphql subscription started"); GraphQLWebSocket::new(socket, schema, protocol) + .keepalive_timeout(None) .serve() .await; - // println!("connection closed"); + tracing::info!("graphql subscription closed"); }) } #[tokio::main] async fn main() { - tracing_subscriber::fmt().with_ansi(false).init(); + if let Ok(level) = env::var("RUST_LOG") { + tracing_subscriber::fmt().with_env_filter(level).init(); + } else { + tracing_subscriber::fmt().init(); + } let readiness_check_path = env::var(READINESS_CHECK_PATH) .unwrap_or_else(|_| panic!("{READINESS_CHECK_PATH} variable assignment"));