acaloiaro / neoq

Queue-agnostic background job library for Go, with a pleasant API and powerful features.
MIT License
270 stars 4 forks source link

fix(pg): Fixed bug with upper-case channel names. #96

Closed elliotcourant closed 1 year ago

elliotcourant commented 1 year ago

When the queue name is uppercase, the listener will never receive the notification when the job is enqueued. This is done specifically with the enqueuer and consumer being separate neoq instances (server A kicks off a job, server B is listening to perform the work).

elliotcourant commented 1 year ago

Demonstration of the issue:

psql (15.4, server 14.9 (Debian 14.9-1.pgdg120+1))
Type "help" for help.

postgres=# LISTEN UppercaseChannel;
LISTEN
postgres=# SELECT pg_notify('UppercaseChannel', 'foo');
 pg_notify
-----------

(1 row)

postgres=# NOTIFY 'UppercaseChannel';
ERROR:  syntax error at or near "'UppercaseChannel'"
LINE 1: NOTIFY 'UppercaseChannel';
               ^
postgres=# -- NOTIFY does not accept text as input.
postgres=# SELECT pg_notify('UppercaseChannel'::name, 'what about as a name');
 pg_notify
-----------

(1 row)

postgres=# SELECT pg_notify('uppercasechannel'::name, 'what about as a name');
 pg_notify
-----------

(1 row)

Asynchronous notification "uppercasechannel" with payload "what about as a name" received from server process with PID 289.
postgres=# -- What about double quotes?
postgres=# NOTIFY "UppercaseChannel";
NOTIFY
postgres=# -- Nothing
postgres=# UNLISTEN UppercaseChannel;
UNLISTEN
postgres=# -- But if you double quote the listen.
postgres=# LISTEN "UppercaseChannel";
LISTEN
postgres=# -- Now it will work with both.
postgres=# NOTIFY "UppercaseChannel";
NOTIFY
Asynchronous notification "UppercaseChannel" received from server process with PID 289.
postgres=# SELECT pg_notify('UppercaseChannel', 'i work now');
 pg_notify
-----------

(1 row)

Asynchronous notification "UppercaseChannel" with payload "i work now" received from server process with PID 289.
postgres=#
elliotcourant commented 1 year ago

@acaloiaro let me know what your thoughts are here. Since we talked in gitter (or whatever its called? i have no idea lol) we agreed that double quoting all of the channel names is the path forward.

This does do that but not sure if its the way you'd want it to do that or if you have any other thoughts.

elliotcourant commented 1 year ago

@acaloiaro added in your suggestions, rebased and squashed down to two meaningful commits!