billyfung / python-postgres-pubsub

NOTIFY + LISTEN with python and psycopg2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Postgres Asynchronous Notification

This is just for playing around with Postgres functionality of LISTEN and NOTIFY https://www.postgresql.org/docs/12/libpq-notify.html

Beats having to set up another application if already using Postgres as the backend.

Set up

docker-compose up

Postgres db with a table jobs Python process that checks jobs_status_channel on Postgres

When both are running, insert into the table jobs to get a notification in the python worker.

insert into jobs(client_id, status, status_change_time) values ('45', 'new', now())

The worker will then pick up the notification.

worker    | listening to jobs_status_channel testdb@db
worker    | Timeout
worker    | Got NOTIFY: 45 jobs_status_channel 7
worker    | Timeout

About

NOTIFY + LISTEN with python and psycopg2


Languages

Language:Shell 78.3%Language:Python 11.3%Language:PLpgSQL 7.9%Language:Dockerfile 2.4%