Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better dynamic runtime queue selection support #11

Open
prabirshrestha opened this issue Oct 19, 2022 · 3 comments
Open

Better dynamic runtime queue selection support #11

prabirshrestha opened this issue Oct 19, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@prabirshrestha
Copy link

My app choose dynamically between sqlite and postgres. Is it possible to support AnyPool from sqlx instead of using only SqlitePool for SqliteQueue::with_pool(anypool)?

I would also like to store queue in struct but it currently requires specifying JobHandle?

pub struct AppState {
  queue: Arc<Queue>,
}

let queue = match anypool.any_kind() {
    AnyKind::Postgres => PostgresQueue::with_pool(anypool),
    AnyKind::Sqlite => SqliteQueue::with_pool(anypool),
    AnyKind::MySql => MySqlQueue::with_pool(anypool),
}

let appstate = AppState { queue };

For now it doesn't matter much since aide-de-camp only supports sqlite, but would like to make it work for generic cases where I can easily swap the queue.

@andoriyu
Copy link
Collaborator

@prabirshrestha AnyPool doesn't work with query! macros. That's the main obstacle. Also, for PostgreSQL, the plan is to use NOTIFY and some other PostgreSQL features. That only works with Pool<Postgres>.

I would also like to store queue in struct but it currently requires specifying JobHandle?

I haven't thought about this. In our codebase, Queue is stored in database-specific type, so this issue never surfaced. We might be able to make JobHandle into a concrete type and move functionality into Queue itself, therefore removing the associated type from Queue completely.

However, Queue, I think, trait isn't object safe anyway because all useful functions are generic over job type submitted.

@prabirshrestha
Copy link
Author

It is a bummer that it wouldn't work. In the mean time I have opened launchbadge/sqlx#2162.

let queue: AnyQueue = match anypool.any_kind() {
   AnyKind::Postgres => PostgresQueue::with_pool(any_pool.try_into().unwrap()).into(),
   AnyKind::Sqlite => SqliteQueue::with_pool(any_pool.try_into().unwrap()).into();
}

Might be similar like sqlx, instead of having generic Queue, it should have AnyQueue? For those that want to support multiple they would use AnyQueue and they can always go back to PostgresQueue or SqliteQueue if they need more control.

@andoriyu
Copy link
Collaborator

andoriyu commented Oct 20, 2022 via email

@andoriyu andoriyu added the enhancement New feature or request label Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants