Cherrypy and SimpleDB with boto - cherrypy

Anyone using Cherrypy and Boto? Any issues? Threads? Any simple examples out there?
I'm wondering where to put the initial boto.connect_sdb statement and whether I can save a domain object or have to call get_domain as I handle every page.

I haven't specifically used boto with CherryPy but there are certainly examples (e.g. botoweb) of it being used in similar frameworks. The main things about SDBConnection objects (or any connection object in boto) is that they use httplib under the covers and that is not threadsafe so you can definitely re-use and persist connection and Domain objects but make sure each thread has it's own.
Hope that helps.

Related

Can I store socket.io socket in redux store? (and call its functions)

I am trying to store a socket created for the client in App.js in my Redux store? I am not sure if this is even a good idea or not, but I want to be able to access the same socket in multiple components, so I thought I could just do it like I did with other objects.
Howerever, the things I stored until now in my redux store are strictly objects with fields in them, I have never stored an object that had functions.
When I try to call a function of the stored socket, I get:
TypeError: this.props.socket.emit is not a function.
Which I guess means that I can't store class entities using Redux. Is this correct?
What would be the right solution here?
The best method to do something like this would be to isolate all code that deals with sockets and expose only those functions that your components call (something like socket.send(message: string) to send message etc).
Don't worry about importing the same module/file again and again, as no matter how many times you import/require it, the same instance is returned. So it's safe to isolate the socket functions and import them wherever needed.
Also, Redux is a state management library, therefore please don't expect it to handle functions and other advanced functionality.

Why are there two OrderLockManager implementations in Broadleaf?

In Broadleaf, both SessionOrderLockManager and DatabaseOrderLockManager can be used by CartStateFilter to serialize user requests.
It appears that the former locks on the session associated with the request, and the latter locks on the order embedded in the request body.
My question is that, why both implementations exist? Are there differences in the provided semantics? Are there scenarios where session-based locks won't suffice? (I found through git history that the database lock implementation is introduced after.)
Many thanks!
p.s. I'm not familiar with HTTP sessions. Please correct me if any statement is wrong.
[Edit] Here's another related question: why use locks at all? It seems that marking the service methods #Transactional suffices.

Actionlogging with Node

I am quite sure that I am not the first person on the planet trying to implement the following, but I am sure that I am not able to find a good guide how to do it.
Our node backend is setup quite like a MVC to say so.
View = Express Server offering our api
Controller = Library, a set of controller functions to manage our data
Model = Our mysql database, it's Javascript DAO respectively (since our usecase is quite unique we need to write own DAO's and can not go let's say for js-data.
The challenge we face now, is:
As a developer, I want to keep our library clean from overhead for developers.
On the other side, as a database administrator I clearly want to know who did what modification and so on
Until now I tried to keep the 'user' object out of the library, since I do not want all controller functions to look like
function ctrl(param1, param2, param..., user)
Going for this would mean, we have to pass around User objects all the time, which would make it a pain to code inside the libraries.
On the other hand, I can not find any other approach in node/express to somehow get knowledge about the user without passing it (since we do not really have sessions, at least not yet in our code).
TL:DR; I do want to action log all database modifications, but do not want to pass around a User object all the time.
Is there any known approach for that challenge which does scale and is 'best practice'?
Thanks in advance

Best way to store answers from users in Facebook bot chat?

Building a Facebook messenger bot using Claudia JS and plan on hosting on AWS Lambda.
I want to ask the user a series of questions.
When a user responds with an answer, I need to save that for later and once I have all the information I need, I will pass the answers to a function.
What is the best way to save this information?
I was thinking some caching layer such as redis but because that is stored in RAM I will lose it when lamda server shuts down. Mongodb apparently has a lot of overheads when connecting but will at least be persistent.
Perhaps just a simple mySQL server?
How does everybody else do it? I feel like there is a simple solution that I am missing.
I will first answer the part about how I'm doing it: I'm using a MongoDB. I toyed with the ideas you mentioned, but quickly crossed out in-memory solutions (Memcached, Redis) with the same reason. My final solution came down to either a relational DB or a noSQL like MongoDB. To be honest, at my project's scale, I did not think about robustly comparing performance between DB types.
With my particular feature "roadmap," I decided to go with Mongo to approach a more "OOP" style when dealing with the user "object" without having to explicitly define a user class, thanks to the normalized structure of Mongo. I understand the same could be done for MySQL, too, just that processing json data is more "object-like" for me and flask, i.e. user = getUserFromMongo, which gives me a dict in Python then I can just do user['first_name']. The codes belows will explain this simplicity:
(Somehow this was feeling like... not having to write SQL commands for simple database interaction in Rails)
My user object data on MongoDB
Finally, as to how I manage user input, I adopted Wit.ai's concept of context. I don't know how they do it exactly, but a context to me is the type of conversation purpose that is going on. I use it like a stack, and as soon as the current context is done, pop it off the context data of the user. For every message the bot receives, the program will get the current context and direct the flow. Whenever an unknown error occurs (exceptions handling), most likely because the user is saying something the bot doesn't understand, I clear the context data, too.
The good part about MongoDB is that I can shape the context however I want and treat it just as an object. A simple one is like {name: yelp-search, stage:ask-for-user-location}, and I imagine complex ones could be built on that structure, too. Of course, a stack implementation of the context does not deal with complex conversation with complex past reference.
I put my project on Github if you want to take a look at it.
i have also used mysql for chatbot but i have used NodeJS for the backend app.For that mysql module would be very helpful.
You need to store users' current state for the question answer session and also store the answer itself from the user and you need to make a switch or if-else-if case for asking questions to user based on its state as switch(state) and in cases of switch just update it's state.and you have user's facebook-id in event object of chatbot so that you can store data of each user individually with their state and question-answer in different table.
For e.g. define flags{1,2,3}
user's state will be 1 in begining so ask him for e.g. question-1
only,and store this as answer-1, you can do this by it's state
checking, and after this update status to 2.
so,in this way you can ask each individual student question as per
their state and answer him.
I've done the same in exact above manner.
Hope this would be helpful to you.

ServiceStack and concurrency

We're evaluating ServiceStack and have found that all example hosts only allow a single request to be processed at a time. If you add a Debug.WriteLine and Thread.Sleep to any entry point, this is easy to see.
I'm assuming we're either missing some setting or are missing a pretty big point with how ServiceStack should be used.
Thanks,
Ross
This actually was a mistake in how we were testing ServiceStack. We were using the same browser but separate tabs/windows, which actually blocks itself from making concurrent requests. Once using two different browsers (e.g. IE and Chrome), we were able to witnesse ServiceStack handling two requests at the same time.

Resources