I'm looking for a way to trigger an event on app engine when a User is created. I have something like
def create_user(data):
user = new User(data)
user.put()
trigger('user_created', user)
return user
This way, external modules may be able to modify the entity when a new user is created. I imagine I could add something like
add_hook('user_created', some_function)
to external modules (on app initialization). This function would add fields to the entity like
def some_function(user):
user.data = 'some value'
What would be the best way to开发者_运维技巧 accomplish this on app engine ?
Generally this is something you would handle with the task queue. When you create a new user, fire off a batch of tasks to do whatever follow-up work is appropriate. You can define the list of tasks elsewhere, and override the put()
method of your User model to enqueue them.
This is kind of a hook enforced within your model. If you need a hook enforced at the datastore, you can try the new Prospective Search API. I haven't tried it, but according to the docs, you can specify a model, a query, and a task handler URL that will be called when new entities matching the query are created.
精彩评论