google-app-enginetimerscheduled-taskschannel-api

Multi-user timer with Google App Engine


We are implementing multi-user timer with Google App Engine. When the timer ends we need to do some calculations and send results to users. Several users should be able to start and pause the timer from different browsers. We will use Channels API for communication. How could we trigger the calculations at specific time?

One idea that we have is, when the timer starts, to create a push task with eta set to timer finish time. When that task runs, check for timer state which is stored in memcache or datastore, and create another task if the state was modified due to pausing the timer. If the timer is finished the task launches the calculations. Are there better approaches, since there is no guarantee that the task will run exactly at eta?


Solution

  • You could have a constantly repeating task (re-enqueing itself, eventually with a delay specified in seconds) which would check the timer state and perform the calculations if appropriate or just return if not.