Shiania White
Shiania White

Reputation: 455

App Engine - Scheduling repeating actions initiated by a user?

I'm trying to figure out a way to schedule repeating actions (with a fairly short repeat time) with the initialization caused by some user action. Neither tasks nor cron seems to fit this quite right. Cron doesn't seem to appropriate for user initialized things and tasks don't seem to be appropriate for repeating schedules.

I want to have the user do something which will then start a repeating action. The action should be taken every 5 seconds. Eventually when the user does something else, the repeating action is ended.

Is there some other part of App Engine that I don't know about that would be best for handling this? Or is there a good way to go about doing this with tasks or cron? Or should I be doing something else entirely? Thanks!

Upvotes: 1

Views: 50

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

You have two options. I don't know all of your requirements, so I list both.

  1. When a user initiates an action, an entity is saved to the Datastore (e.g. "ActionEntity"). A cron job periodically queries the datastore, and if an ActionEntity is present, creates a task to be performed. When a user cancels an action, ActionEntity is deleted, so the next time this cron job queries for it, it won't see it and won't create a task.

  2. When a user initiates an action, a task is created. When a task finishes, it checks if a user cancelled an action. If not, it creates another task to be executed with a specified delay. And so on.

UPDATE:

If you need a very precise execution, you may have to use a timer in your instances, but then you will have to design your own fail-over mechanism, possibly using Memcache.

Upvotes: 1

Related Questions