-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding message worker spawning on pgsql notify event
- Loading branch information
1 parent
63c572f
commit cc837ff
Showing
2 changed files
with
38 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
pub async fn run() { | ||
// TODO: worker implementation | ||
use { | ||
sqlx::{postgres::PgListener, PgPool}, | ||
std::sync::Arc, | ||
}; | ||
|
||
pub async fn run( | ||
pg_pool: &Arc<PgPool>, | ||
relay_client: &Arc<relay_client::http::Client>, | ||
) -> Result<(), sqlx::Error> { | ||
let mut pg_notify_listener = PgListener::connect_with(pg_pool) | ||
.await | ||
.expect("Notifying listener failed to connect to Postgres"); | ||
pg_notify_listener | ||
.listen("notification_for_delivery") | ||
.await | ||
.expect("Failed to listen to Postgres events channels"); | ||
|
||
loop { | ||
let notification = pg_notify_listener.recv().await?; | ||
tokio::spawn({ | ||
let pg_pool = pg_pool.clone(); | ||
let relay_client = relay_client.clone(); | ||
async move { process_message(&pg_pool, &relay_client, notification.payload()).await } | ||
}); | ||
} | ||
} | ||
|
||
async fn process_message( | ||
_pg_pool: &Arc<PgPool>, | ||
_relay_client: &Arc<relay_client::http::Client>, | ||
_message_delivery_id: &str, | ||
) { | ||
// TODO: implement | ||
} |