The Environment is a container for request handlers, managed objects and other runtime settings as well as the tornado.web.Application settings.
There are two cases where you will need to work with the it: during the bootstrapping phase you may change paths to look for configuration files and you will add the request handlers to the environment. In addition to that you can also use it from within a request handler in and access managed objects, such as HTTP clients that can be used accross a number of client libraries for connection pooling, e.g.
Environment for supercell processes.
Add a handler to the tornado.web.Application.
The environment will manage the available request handlers and managed objects. So in the Service.run() method you will add the handlers:
class MyService(s.Service): def run(): self.environment.add_handler('/', Handler)
Add a health check to the API.
Add a managed instance to the environment.
A managed object is identified by a name and you can then access it from the environment as an attribute, so in your request handler you may:
class MyService(s.Service): def run(self): managed = HeavyObjectFactory.get_heavy_object() self.environment.add_managed_object('managed', managed) class MyHandler(s.RequestHandler): def get(self): self.environment.managed
The list containing all paths to look for config files.
In order to manipulate the paths looked for configuration files just manipulate this list:
class MyService(s.Service): def bootstrap(self): self.environment.config_file_paths.append( '/etc/myservice/') self.environment.config_file_paths.append('./etc/')
Determine the configuration file name for the machine this application is running on.
The filenames are generated using a combination of username and machine name. If you deploy the application as user webapp on host fe01.local.dev the configuration name would be webapp_fe01.local.dev.cfg.
Create the tornado application.
|Parameters:||config – The configuration that will be added to the app|
Return the supercell.api.cache.CacheConfig for a certain handler.
Return the timedelta for a specific handler that should define the Expires header for GET and HEAD requests.
Simple property access for health checks.
The dictionary passed to the tornado.web.Application containing all relevant tornado server settings.