The shared functionality involves DB access, so as far as I can tell it cannot be abstracted into modules that would then be imported with a normal import. But I will take a look at the exec_environment thing, which may be what I'm after.
On Thursday, January 5, 2017 at 8:26:49 AM UTC-8, Anthony wrote: > > Check out > http://web2py.com/books/default/chapter/29/04/the-core#Execution-environment > and http://web2py.com/books/default/chapter/29/04/the-core#Cooperation. > > You might also consider whether the shared functionality can be abstracted > into Python modules that can be imported by multiple applications. > > Anthony > > On Thursday, January 5, 2017 at 12:54:59 AM UTC-5, Brendan Barnwell wrote: >> >> I have a situation where I have (or am going to have) multiple >> applications running on a single web2py instance. Each application will do >> its own thing, but they are all using the same databases. Some of the >> applications may serve as backend API endpoints where certain kinds of data >> can be retrieved. Other applications may sometimes want to make calls to >> these endpoints to get the data and use it in their own operations. >> >> So what I'm wondering is: is there any way for one application to call a >> controller in another application and get the raw data that WOULD be used >> to build an actual HTTP response, but without actually going through the >> network? That is, suppose I have and endpoint /app1/controller1/get_data >> and another /app2/controller2/do_something . Inside do_something, I want >> to get the data that get_data gets. >> >> Currently I have get_data set up as a JSON service. I could certainly >> make the request to the other endpoint, but that involves a number of extra >> steps: generating an outgoing HTTP request, serializing any data to passed >> with it, generating the incoming HTTP request object, deserializing the >> request data, then serializing the response and deserializing it again when >> it's received. What I really want to do is to just call the function >> get_data AS IF a request had been submitted, but have everything happen on >> the server, without any network requests actually happening. As far as I >> can tell, I can't in any way "import" the get_data function from the other >> app, because if I call it, it won't have the magic environment set up >> (e.g., "db" won't exist for it to do its database queries). I would even >> be okay with "pretending" like I was doing a request, as long as web2py >> could somehow realize that the app I want to call is running on the same >> web2py instance, and call it "directly" instead of submitting a network >> request to itself. >> >> I realize that this architecture involves apps that are more >> interdependent than they would be in a "by the book" web2py project. But >> basically the idea is that the functionality of the apps is independent, >> and in theory they should work if running on different servers, by making >> real requests. It's just that, IF they are running on the same server, I'd >> like to communicate between them without going through the network, to >> improve performance. Also, I can't really change the architecture since >> it's for a project I'm working on but don't ultimately control. >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.