From 708e35255210cee72d346a392c2334b6216fd23b Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 17 Oct 2024 10:09:07 -0400 Subject: [PATCH 1/5] refactor(torii): different tasks for torii services --- bin/torii/src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 9e776f3bfc..5742fc32bf 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -308,12 +308,17 @@ async fn main() -> anyhow::Result<()> { .await?; } + tokio::spawn(async move { + proxy_server.start(shutdown_tx.subscribe()).await.unwrap(); + }); + tokio::spawn(graphql_server); + tokio::spawn(grpc_server); + tokio::spawn(async move { + libp2p_relay_server.run().await; + }); + tokio::select! { res = engine.start() => res?, - _ = proxy_server.start(shutdown_tx.subscribe()) => {}, - _ = graphql_server => {}, - _ = grpc_server => {}, - _ = libp2p_relay_server.run() => {}, _ = dojo_utils::signal::wait_signals() => {}, }; From d14c213557c9452902ef302196d4ec2c20e18497 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 17 Oct 2024 10:14:12 -0400 Subject: [PATCH 2/5] handles in select --- bin/torii/src/main.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 5742fc32bf..c6be568dae 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -308,18 +308,26 @@ async fn main() -> anyhow::Result<()> { .await?; } - tokio::spawn(async move { - proxy_server.start(shutdown_tx.subscribe()).await.unwrap(); + let proxy_server_handle = tokio::spawn(async move { + proxy_server.start(shutdown_tx.subscribe()).await }); - tokio::spawn(graphql_server); - tokio::spawn(grpc_server); - tokio::spawn(async move { - libp2p_relay_server.run().await; + let graphql_server_handle = tokio::spawn(async move { + graphql_server.await + }); + let grpc_server_handle = tokio::spawn(async move { + grpc_server.await + }); + let libp2p_relay_server_handle = tokio::spawn(async move { + libp2p_relay_server.run().await }); tokio::select! { res = engine.start() => res?, _ = dojo_utils::signal::wait_signals() => {}, + _ = proxy_server_handle => {}, + _ = graphql_server_handle => {}, + _ = grpc_server_handle => {}, + _ = libp2p_relay_server_handle => {}, }; Ok(()) From 7f46ab9971cd3f39462215052caf79152ac8e932 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 17 Oct 2024 10:16:07 -0400 Subject: [PATCH 3/5] handle for indexer too --- bin/torii/src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index c6be568dae..557067ad58 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -308,26 +308,33 @@ async fn main() -> anyhow::Result<()> { .await?; } + let engine_handle = tokio::spawn(async move { + engine.start().await + }); + let proxy_server_handle = tokio::spawn(async move { proxy_server.start(shutdown_tx.subscribe()).await }); + let graphql_server_handle = tokio::spawn(async move { graphql_server.await }); + let grpc_server_handle = tokio::spawn(async move { grpc_server.await }); + let libp2p_relay_server_handle = tokio::spawn(async move { libp2p_relay_server.run().await }); tokio::select! { - res = engine.start() => res?, + res = engine_handle => res??, + res = proxy_server_handle => res??, + res = graphql_server_handle => res?, + res = grpc_server_handle => res??, + res = libp2p_relay_server_handle => res?, _ = dojo_utils::signal::wait_signals() => {}, - _ = proxy_server_handle => {}, - _ = graphql_server_handle => {}, - _ = grpc_server_handle => {}, - _ = libp2p_relay_server_handle => {}, }; Ok(()) From b5ddd993bc7267746966a45ec5f740cbf894950d Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 17 Oct 2024 10:16:31 -0400 Subject: [PATCH 4/5] fmt --- bin/torii/src/main.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 557067ad58..456d17b9e3 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -308,25 +308,12 @@ async fn main() -> anyhow::Result<()> { .await?; } - let engine_handle = tokio::spawn(async move { - engine.start().await - }); - - let proxy_server_handle = tokio::spawn(async move { - proxy_server.start(shutdown_tx.subscribe()).await - }); - - let graphql_server_handle = tokio::spawn(async move { - graphql_server.await - }); - - let grpc_server_handle = tokio::spawn(async move { - grpc_server.await - }); - - let libp2p_relay_server_handle = tokio::spawn(async move { - libp2p_relay_server.run().await - }); + let engine_handle = tokio::spawn(async move { engine.start().await }); + let proxy_server_handle = + tokio::spawn(async move { proxy_server.start(shutdown_tx.subscribe()).await }); + let graphql_server_handle = tokio::spawn(async move { graphql_server.await }); + let grpc_server_handle = tokio::spawn(async move { grpc_server.await }); + let libp2p_relay_server_handle = tokio::spawn(async move { libp2p_relay_server.run().await }); tokio::select! { res = engine_handle => res??, From 655c4010f4064bb04144e6d6af9a782409d1a658 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 17 Oct 2024 10:21:32 -0400 Subject: [PATCH 5/5] c --- bin/torii/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 456d17b9e3..65ba340c16 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -311,8 +311,8 @@ async fn main() -> anyhow::Result<()> { let engine_handle = tokio::spawn(async move { engine.start().await }); let proxy_server_handle = tokio::spawn(async move { proxy_server.start(shutdown_tx.subscribe()).await }); - let graphql_server_handle = tokio::spawn(async move { graphql_server.await }); - let grpc_server_handle = tokio::spawn(async move { grpc_server.await }); + let graphql_server_handle = tokio::spawn(graphql_server); + let grpc_server_handle = tokio::spawn(grpc_server); let libp2p_relay_server_handle = tokio::spawn(async move { libp2p_relay_server.run().await }); tokio::select! {