-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
self.tokens does not persist between requests #8
Comments
It seems that there is another error that the persisting of tokens because self is maybe not the Subscriptions object in handler (so self.tokens is not defined). here is a really quick fix (I didn't test it), tell me what you think about it : https://gist.github.com/SamyPesse/795258b15c12f14a6058 But it's a good idea to implement sort of user defined get_user callback with a default in-memory storage for the users. (Sorry for my english). |
In my case, # Add view for subscription
def handler():
data = json.loads(flask.request.data)
userid = data["userToken"]
if not userid in self.tokens:
self.app.logger.error("Callback for a non-existent user")
else:
user = User(app=self.app, tokens=self.tokens[userid])
if data["collection"] == "timeline":
for action in data["actions"]:
self.call_endpoint("action."+action["type"], user)
elif data["collection"] == "locations":
self.call_endpoint("location", user)
return '', 200
self.app.web.add_url_rule('/glass/callback/%s' % subscription_id, 'callback_%s' % subscription_id,
handler, methods=["POST"]) I will implement a user defined get_user callback with an in-memory fallback and see how that works. If all is well with it I will submit the fixes as a pull request later today or tomorrow. |
OK, I think it could be a good way to implement it in another class and so user can inherit this class to create his own backend storage for users (for example to store in mysql or mongodb). And let user build application with its own backend storage or use the default one "in memory", example :
|
I agree. |
I'm working on some of this functionality along with some bug fixes and enhancements. I've added an ext package with an appengine datastore backend as well as an appengine memcached backend. You can see a compare if it here: https://github.com/Trii/glass.py/compare/master...pluggable-user-storage |
I'm working on handling glass callbacks with subscriptions and on https://github.com/SamyPesse/glass.py/blob/master/glass/subscriptions.py#L51
there is a check to see if the callback json data matches an existing user token. Since self.tokens does not persist between requests this always fails. I am fixing a few bugs and I figured while I was at it I would implement a different solution for this.
Does this work for you in the emulator or is it mostly untested code? In order to keep this code as platform agnostic as possible I was thinking of implementing some sort of user defined get_user callback so you can make your own depending on your storage needs. What do you think?
The text was updated successfully, but these errors were encountered: