How to properly exec a long-running database operation during the launching phase? #2187
-
Hi all, I am trying to make a long-running (~1min) function call which queries the database and constructs some data objects for upcoming usage. But it will give me a runtime panic if I create a
a minimal sample code snippet will be like this:
It's a bit strange to me that although the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Looking into the |
Beta Was this translation helpful? Give feedback.
Looking into the
postgres
crate, it looks like it starts it's own async runtime and runs an async client on the runtime it creates. It's technically a sync client (since it doesn't need an async runtime), but it can't actually be started within a tokio runtime due to some things tokio does. The simple solution here would actually be to use something liketokio-postgres
, an async client (since Rocket already creates a tokio runtime, you might as well use it). Thepostgres
crate actually usestokio-pos…