What’s the easiest way to take an existing Django view and make it “real time” via long polling?
2nd October 2010
I’d advocate decoupling your long polling endpoints entirely from the rest of your web app stack. Personally I like Node.js for this, but Tornado would work just fine too (I’ve experimented successfully with Tornado long polling in the past).
I wouldn’t even bother talking to the database from the long polling code. Instead, set it up as a sort of WebHook system. Your client starts long-polling a URL on the Tornado or Node.js server (which could be running on a sub-domain of your regular site, or could just be a separate part of the URL space proxied by something like nginx). That long polling server is set up to listen for WebHook POSTs to a protected URL, which can come from a backend process, a Celery worker, a Cron job or the Django web app itself. When the POST comes in, the long poll is instantly returned.
More recent articles
- Weeknotes: datasette-enrichments, datasette-comments, sqlite-chronicle - 8th December 2023
- Datasette Enrichments: a new plugin framework for augmenting your data - 1st December 2023
- llamafile is the new best way to run a LLM on your own computer - 29th November 2023
- Prompt injection explained, November 2023 edition - 27th November 2023
- I'm on the Newsroom Robots podcast, with thoughts on the OpenAI board - 25th November 2023
- Weeknotes: DevDay, GitHub Universe, OpenAI chaos - 22nd November 2023
- Deciphering clues in a news article to understand how it was reported - 22nd November 2023
- Exploring GPTs: ChatGPT in a trench coat? - 15th November 2023
- Financial sustainability for open source projects at GitHub Universe - 10th November 2023
- ospeak: a CLI tool for speaking text in the terminal via OpenAI - 7th November 2023