4 ms·
Edit: Swampdragon runs in a Tornado IO loop for real time functionality, and uses Redis Pub/Sub for actual Pub/Sub messaging. It's more like Django bolted to To
by andor 12y ago
Edit: Swampdragon runs in a Tornado IO loop for real time functionality, and uses Redis Pub/Sub for actual Pub/Sub messaging. It's more like Django bolted to Tornado than Pub/Sub added to Django.
* Objects are diffed in the python process before saving the new state. They
are diffed with what was loaded from the DB at object initialization time.
https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/models.py#L12 https://github.com/jonashagstedt/swampdragon/blob/master/swa...
* Then, the whole object is stored, and the changes are broadcasted. Since
the whole object is stored, you can get race conditions if multiple server
processes modify it concurrently.
https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/models.py#L66 https://github.com/jonashagstedt/swampdragon/blob/master/swa...
* Messages are sent from Python to Redis Pub/Sub channels, and received by
Python again. If the Python process has (Websocket) subscribers for the channel,
messages are delivered. The indirection over Redis allows having multiple
Python processes.
- hagsteel 12y agoIt's not quite accurate to say it's like Django bolted to Tornado. Tornado deals with the websockets, but everything else is Django. You could easily add this to an existing Django project. It's also using Django settings, etc. You are right about the potential race conditions using the self publishing model, but you don't have to use the self publishing model though, it works just as well using the routers + serializers.