PaulGilmartin / django-pgpubsub

A distributed task processing framework for Django built on top of the Postgres NOTIFY/LISTEN protocol.
Other
245 stars 12 forks source link

Strange behavior for recovery and multiple handlers #84

Open spapas opened 3 weeks ago

spapas commented 3 weeks ago

Hello friends, I'm using this app on a django project in windows and getting these two problems:

1 I want to store the notifications so they won't get missed. This seems to be working however when I run the worker with dj listen --recover --worker-start-method=spawn I get something:

2024-11-04 12:33:20,694 INFO Processing all notifications for channel pycensus.oldcensus.channels.SampleChannel
2024-11-04 12:33:20,695 INFO Found notifications: <generator object QuerySet._iterator at 0x0000025C8CB4BA40>
2024-11-04 12:33:20,708 INFO Listening for notifications...

however the handlers for the old notifications are not running (I've got a print function there and it doesn't display)

2

When I run two handlers together I get the following messages on both:

2024-11-04 12:43:37,311 INFO Processing notification for pycensus.oldcensus.channels.SampleChannel
2024-11-04 12:43:37,315 INFO Could not obtain a lock on notification 2787277

I would expect one of the handlers to obtain the lock.

If it helps, here is the definition of my channel:

@dataclass
class SampleChannel(Channel):
    lock_notifications = True
    x: int
    y: str

and my handler

@pgpubsub.listener(channels.SampleChannel)
def update_post_reads_per_date_cache(x: int, y: str) -> None:
    print(f"Updating cache for model {x} on {y}")

I'm using Django==5.1.2, django-pgpubsub==1.3.0, psql server 15.8 and windows 11.