1

Background: I'm trying to build a survey app where users can add answers to the survey and have these answers pushed to other users (e.g. if the question is "What is your favorite programming language?" and I didn't include Haskell, the user can add "Haskell" as an answer, and it will show up on everyone's browser). I'm planning to use long polling to achieve this.

My conceptual approach: The approach that I've settled on is setting up something like an observer pattern (or maybe it is exactly like the observer pattern. I'm new to design patterns).

The steps would be something like this: The browser makes a request to /app/longpoll, which spins up a view which 1. uses time stamps to check if any changes have occurred, and if so returns those changes, or 2. registers itself with an event delegator and waits for a message. Then when a browser makes a request to /app/UpdateSurvey a view gets fired up which 1. updates the survey, and 2. informs the event delegator that the survey has been changed.

My question: Given that this is a sane approach to solving this problem, how do I implement it? It seems like I need a standing process to serve as the event delegator, but I'm really not sure what this looks like. How do I find this process to register with it? How do I register with it? How do I make this process exist in the first place? What happens if this process is busy delegating events when a answer gets added to the poll?

I recognize that this is asking for a long answer, and has probably been solved by other people, so article/book recommendations are also encouraged.

canisrufus
  • 665
  • 2
  • 6
  • 19
  • 1
    how about websockets instead of long polling, then you can push to users with the page open (subscribers)? – cerberos Dec 20 '12 at 15:50
  • @cerberos my target population primarily uses internet explorer. – canisrufus Dec 20 '12 at 15:53
  • This really sounds like something that has been solved before. I strongly urge you to look for packages which implement this for django, and to consider other networking-related tools for python. – Marcin Dec 20 '12 at 18:00
  • @Marcin I wasn't clear about this, but my interest is primarily educational (with a secondary goal of building a working survey tool). It looks like python sockets would work, but maybe not be optimal. If I can find them, I'll look at how other tools implement this. – canisrufus Dec 20 '12 at 18:33
  • @canisrufus Nevertheless, I strongly suggest that you look at existing implementations to see the techniques they have used. – Marcin Dec 20 '12 at 18:48
  • This is fully possibile with nodejs and socket.io. If you have the skill and urge maybe it would be possible to steal code from that or even port it? – Rickard Zachrisson Dec 20 '12 at 20:15

1 Answers1

1

This is a different solution to the one you've asked for but how about using a post_save signal when a new question is added that uses websockets to push to any user who has the page open (subscribed clients)?

Edit: Ah, IE - use Juggernaut in place of websockets (will still use websockets if the browser supports them), works on IE6 (I think) and 7 (I know)

César
  • 9,939
  • 6
  • 53
  • 74
cerberos
  • 7,705
  • 5
  • 41
  • 43
  • "Juggernaut has been deprecated! Read why here." So may be an unstable solution but could work. – Rickard Zachrisson Dec 20 '12 at 20:15
  • @Rickard Zachrisson deprecated because modern browsers/HTML5 provides native solutions, IE doesn't support those so Juggernaut can be used instead. – cerberos Dec 21 '12 at 12:09