-
SetupI have a Rocket application which serves a bunch of challenge progress to users from the database. In theory this can be done entirely in isolation of the rocket app, but it would be very nice to share as much handling code as possible (and leave the potential for other non-polling behaviour like webhooks for the api for which the rocket app). ProblemHowever I can't see a way to schedule any tokio tasks that have the right kind of access to create a [rocket_sync_db_pools::Connection] (which is generated so the type is pretty hidden too) or otherwise trigger the request guard to create the database connection. QuestionBasically I want to spawn some repeated tasks which can access Rocket state akin to request guards in order to acquire the same DB Connection. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I had the same problem and I ended up using r2d2 pools directly, plus my own cron-based loop which utilizes async version of sleep between scheduled tasks. Coupling your own scheduler with Rocket might not worth it, even if it's possible, given the only thing you want to share is a connection pool. Pools are cheap, and even if both of those components also share a few functions, that should be fine too, as long as those functions accept single connections instead of pools (they'd have the same type no matter which pool they're coming from). Using Rocket-focused connection pool outside of Rocket wouldn't make much sense anyway. Hopefully someone can provide more information on the possibility of neatly integrating schedulers within the Rocket itself. Again, it's not in the docs so I wouldn't put much hope on that being possible |
Beta Was this translation helpful? Give feedback.
-
I think this is essentially issue #1187.
Instead, we focused efforts on direct support for async database pools (including *(currently only in the |
Beta Was this translation helpful? Give feedback.
-
Thanks folks, I'll implement my own pools like you suggest - and keep my eyes peeled for rocket_db_pools! |
Beta Was this translation helpful? Give feedback.
I think this is essentially issue #1187.
rocket_sync_db_pools
does not currently have this capability and I'm generally in agreement with @bubelov on adding your own secondary database pool given this limitation. It is likely possible to implement this, but it might necessitate even further redesign on top of the async compatibility work.Instead, we focused efforts on direct support for async database pools (including
deadpool-postgres
andsqlx
) in a new craterocket_db_pools
*. One of the goals forrocket_db_pools
was to solve this exact limitation! The database type now implementsDeref
to the underlying pool type, so one could callSomeDb::fetch(&rocket).clone()
to get an independent h…