Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger event on app engine

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 ?

like image 329
guigouz Avatar asked Apr 20 '26 19:04

guigouz


1 Answers

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.

like image 91
Drew Sears Avatar answered Apr 22 '26 10:04

Drew Sears



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!