closeio / tasktiger

Python task queue using Redis
MIT License
1.42k stars 80 forks source link

[PoC] Queue notification to optimize polling #257

Open neob91-close opened 1 year ago

neob91-close commented 1 year ago

This PR is a PoC for an optimised way to poll queues. Tests were deliberately omitted at this stage.

The way it works is that the key t:queued_cache_token:<queue root> (I welcome better naming here) is updated with a random token whenever a task is added to that queue.

The workers will monitor the tokens related to the queues they're interested in and do the expensive queue poll only when any of them change (or if an hour elapsed since the last poll, as a safeguard).